2011-04-07 42 views

cevap

72

sadece posta kodu veya şehir ve devlet ile {posta kodu} replaceing aşağıdaki çağrı Could http://maps.googleapis.com/maps/api/geocode/json?address= {posta kodu}

Google Geocoding İşte

JavaScript kullanarak coğrafi kod Nasıl bir ile bir bağlantı : Geocode walk-thru.

var lat = ''; 
    var lng = ''; 
    var address = {zipcode} or {city and state}; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     lat = results[0].geometry.location.lat(); 
     lng = results[0].geometry.location.lng(); 
     }); 
     } else { 
     alert("Geocode was not successful for the following reason: " + status); 
     } 
    }); 
    alert('Latitude: ' + lat + ' Logitude: ' + lng); 
+2

Aynı cevabı yanlışlıkla başka bir iş parçacığına gönderdim, sonra 3 dakika için bir tane daha göndermeme izin vermedi! haha Bu bir adresi ile yapmak izin verecek: http://maps.googleapis.com/maps/api/geocode/xml?address=Mountain+View,+CA&sensor=false dönüş olacak bu yürüyüş thrum içinde 37,3860517 -122,0838511 Tony

+0

eğer zip ile i alt adres, hem de işe woudl? – Scott

+0

Evet, burada test edebileceğiniz bir çalışma örneği. Metin Kutusu sol üst köşede. http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html – Mark

6

Sadece bir ipucu: Eğer gerekiyorsa belirli enlem/Ing sayılar enlem/Ing almak için geometry.location.lat() veya geometry.location.lng() (API for google.maps.LatLng class)

ÖRNEK çağırır: zip kodları dünya çapında benzersiz değildir bu nedenle ülke ISO kodu istekte (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) sağlamak için değer.

örneğin cila (iso kod PL) zipcode 01-210 koordinatları arayan:

https://maps.googleapis.com/maps/api/geocode/json?address=01210,PL

nasıl kullanıcı ülke kodunu almak için? IP adresine bunun için hizmetler, örneğin üzerinde GET isteği yapabilirsiniz vardır tabanlı kullanıcı ülke bilgi almak isterseniz

: http://ip-api.com/json

+0

ipucu için teşekkürler, sadece adresi = 01210 kullanarak doğru bir sonuç vermedi. ek olarak, "PL" ek olarak çalışıyor! – Havrin