15
A
回答
27
只需創建的google.maps.Geocoder
一個實例,並調用其geocode
方法,通過在具備必要的屬性爲它是一個GeocoderRequest
的對象。
這樣:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: /* zip you got from user input */},
function(results_array, status) {
// Check status and do whatever you want with what you get back
// in the results_array variable if it is OK.
// var lat = results_array[0].geometry.location.lat()
// var lng = results_array[0].geometry.location.lng()
});
11
您可以使用此交替:
只需撥打這個網址在jQuery的Ajax和你會得到結果Lat Long網。
示例使用jQuery的Ajax:從谷歌API
$(document).ready(function(){
var zipcode = 695564;
$.ajax({
url : "http://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=postal_code:"+zipcode+"&sensor=false",
method: "POST",
success:function(data){
latitude = data.results[0].geometry.location.lat;
longitude= data.results[0].geometry.location.lng;
alert("Lat = "+latitude+"- Long = "+longitude);
}
});
});
樣品JSON結果:
{
"results" : [
{
"address_components" : [
{
"long_name" : "695564",
"short_name" : "695564",
"types" : [ "postal_code" ]
},
{
"long_name" : "Thiruvananthapuram",
"short_name" : "TVM",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Kerala",
"short_name" : "KL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Kerala 695564, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 8.5894172,
"lng" : 77.0210912
},
"southwest" : {
"lat" : 8.5616185,
"lng" : 76.96664299999999
}
},
"location" : {
"lat" : 8.5753702,
"lng" : 76.99310740000001
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 8.5894172,
"lng" : 77.0210912
},
"southwest" : {
"lat" : 8.5616185,
"lng" : 76.96664299999999
}
}
},
"partial_match" : true,
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}
乾杯..
+1
我試着http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:530016&sensor=false其工作的爐排 – 2016-03-10 14:36:15
相關問題
- 1. 從經緯度獲取郵政編碼
- 2. 從谷歌地圖獲取經緯度
- 3. 從javascript中的緯度和經度獲取郵政編碼
- 4. 英國郵政編碼的地理編碼經度和緯度?
- 5. 從經度,緯度獲取郵政編碼?
- 6. 從經度/緯度獲取郵政編碼
- 7. 從郵政編碼獲取經度/緯度
- 8. 如何獲取郵政編碼的經度和緯度?
- 9. 使用PHP獲取郵政編碼的經度和緯度
- 10. 如何從谷歌地圖獲取經度和緯度的place_id?
- 11. 如何從谷歌地圖獲取緯度和經度?
- 12. 從谷歌地圖獲取緯度和經度
- 13. 從經緯度查找郵政編碼
- 14. android從印度經緯度獲得印度的郵政編碼
- 15. 谷歌地圖經度和緯度
- 16. iphone谷歌地圖獲取地址的經度和緯度
- 17. 黑莓<location>緯度和經度從谷歌地圖緯度和經度
- 18. 獲取緯度/經度附近的郵政編碼列表
- 19. 如何獲取谷歌地圖上的緯度和經度
- 20. 如何獲取谷歌地圖中心的經度和緯度
- 21. 谷歌地圖api javascript獲取經度和緯度?
- 22. 從經緯度獲取郵政編碼+4
- 23. 從經緯度生成谷歌地圖
- 24. 獲得緯度和經度給出郵政編碼和/或地址字符串
- 25. 如何獲得地址的緯度和經度?谷歌地圖
- 26. rails從谷歌地圖使用經緯度獲取地址
- 27. iOS從郵政編碼查找位置(經度,緯度)
- 28. 谷歌地圖經緯度地址
- 29. 如何通過郵政編碼獲取所有緯度和經度點數?
- 30. 如何從谷歌地圖獲取當前的經緯度
每次都遇到'ZERO RESULTS'我嘗試一個郵政編碼。 – Leeish 2014-07-10 17:06:17
您可以嘗試在請求中添加['region'](https://developers.google.com/maps/documentation/javascript/reference?csw=1#GeocoderRequest)並查看是否有助於Google消除該值的歧義。 – 2014-07-10 17:35:19