2011-12-30 115 views
1

嗨,我在我的网站使用Bing地图,并希望经纬度长时间查明Bing地图上的位置。我的问题是在我的网站上,我怎样才能使用PIN码获得经纬度。是否有任何API可以用来通过给出区域PIN码来查询经纬度。我想在后端做。使用一些ajax调用该特定的web api并取回经纬度并将其保存到数据库中,这样我就可以使用该lat来绘制我的bing地图上的位置。如何找到经纬度,使用PIN码的给定区域的长度

我使用的是bing map 7,我需要将lat long值放入一个json对象并传递给Bing地图。

function GetMap() 
{ 
var mapOptions = { 
credentials: "Your Bing Maps Key", 
center: new Microsoft.Maps.Location(47.592, -122.332), // i want these value in my   database 
mapTypeId: Microsoft.Maps.MapTypeId.birdseye, 
zoom: 17, 
showScalebar: false 
} 
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions); 
} 

我可以硬编码,但在我的应用程序给客户端,它是用来增加新的位置,以便在后端我希望它像一个选项,当客户端添加任何新的位置,它会自动保存其经纬度长也。

感谢

+0

我已经完成了使用谷歌API它工程真棒BT我不知道你想要一个基于谷歌的解决方案。由于您正在使用API​​ API。如果你想要基于谷歌的代码,我可以分享它... – aProgrammer 2011-12-30 11:48:48

+0

你请分享它。您是否使用其他api或web服务从pin码查找经纬度。 – ifti 2012-01-03 04:00:09

+0

你可以尝试这个http://lab.iamrohit.in/pincode_finder/以及 – inrsaurabh 2018-01-19 11:47:03

回答

1

使用pincodes获得的纬度,经度值可能不是最好的解决方案,因为虽然流行的PIN码为一个多世纪的仍然是世界各地的not a standard。例如在美国的pincode(邮政编码)通常有5位数字(即06160),并在我的地区,他们通常是6位或更多..

虽然您可以使用街道地址,州,国家和密码来找出几乎世界各地的几乎正确的地理坐标。请参见下面的脚本这就要求谷歌API用于查找纬度,经度值...在这里通过我GPL下捐出此代码社区: -

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"> </script> 

<script src="http://maps.google.com/maps?file=api&v=3&key=ABQIAAAA7j_Q-rshuWkc8HyFI4V2HxQYPm-xtd00hTQOC0OXpAMO40FHAxT29dNBGfxqMPq5zwdeiDSHEPL89A" type="text/javascript"> </script> 
<script type="text/javascript"> 

     var geocoder, location1; 

     function initialize() { 
      geocoder = new GClientGeocoder(); 
     } 
     function prepareQuery(){ 
      var query=''; 
      var a1 = document.getElementById('address1').value; 
      var a2 = document.getElementById('address2').value; 
      var a3 = document.getElementById('address3').value; 
      var cty = document.getElementById('city').value; 
      var stat = document.getElementById('state').value; 
      var cntry =document.getElementById('country').value; 
      var pin = document.getElementById('pincode').value; 

      if(a1 != null && a1!=''){ 
       query = query + a1 + ",";      
      } 
      if(a2 != null && a2!=''){ 
       query =query + a2 + ",";      
      } 
      if(a3 != null && a3!=''){ 
       query = query + a3 + ",";      
      } 
      if(cty != null && cty!=''){ 
       query = query + cty + ",";      
      } 
      if(stat != null && stat!=''){ 
       query = query + stat + ",";      
      } 
      if(cntry != null && cntry!=''){ 
       query = query + cntry + ",";      
      } 
      if(pin != null && pin!=''){ 
       query = query + pin + ",";      
      } 
      //    alert("Prepare Query Returns " +query); 
      return query; 
     } 
     function submitFunc(){ 
      var location = prepareQuery();    
      geocoder.getLocations(location, function (response) { 
       if (!response || response.Status.code != 200) 
       { 
        alert("Sorry, we were unable to geocode the address"); 
       } 
       else 
       {      
        location1 = {latitude: response.Placemark[0].Point.coordinates[1], longitude: response.Placemark[0].Point.coordinates[0], Address : response.Placemark[0].address}; 

        var items = []; 
        $.each(location1, function(key, value){       
         items.push('<li id="' + key + '">' + key +" : "+ value + '</li>'); 
        }); 
        //      alert(items) 
        $("body").append("Results is :-"); 
        $('<ul/>', { 
         'class': 'my-new-list', 
         html: items.join('') 
        }).appendTo('body'); 
       } 
      }); 
     } 

    </script> 

和HTML的样子....

 Line 1 : <input type="text" id="address1" value="" placeholder="Enter first line of address."/> <br></br>    
     Line 2 :<input type="text" id="address2" value="" placeholder="Enter second line of address."/> <br></br>    
     Line 3 :<input type="text" id="address3" value="" placeholder="Enter third line of address."/> <br></br>    
     City  : <input type="text" id="city" value="" placeholder="Enter city name."/> <br></br>    
     State : <input type="text" id="state" value="" placeholder="Enter state name."/> <br></br>    
     Country : <input type="text" id="country" value="" placeholder="Enter country name."/> <br></br>    
     Pin Code : <input type="text" id="pincode" value="" placeholder="Enter pincode value."/> <br></br>    
     <input type="button" name="submitBtn" value="submit" onclick='submitFunc();'/> <br></br> 

     <h3> <strong> Your Results Will be displayed Here . . . .</strong> </h3> 
+0

感谢它是伟大的帮帮我。 – ifti 2012-01-04 10:11:30

1

国地名是所有类型的位置的东西了良好的服务,看看他们提供的服务的列表:

http://www.geonames.org/export/ws-overview.html

你可以使用一个查找邮政编码? api.geonames.org/postalCodeLookupJSON?postalcode=6600 &国家= AT &用户名=演示

+0

感谢您的帮助,但我没有得到任何api或示例代码。请你分享一些代码或任何其他链接,我可以得到任何教程 谢谢 – ifti 2012-01-02 12:24:03

+0

我用这个链接api.geonames.org/postalCodeLookupJSON?postalcode=6600&country=AT&username=demo但它不适合我 – ifti 2012-01-03 04:23:09

相关问题