我只需要一些簡單的示例代碼,它可以告訴我如何從輸入的郵政編碼或城市/州獲取一個latlng元素。從郵政編碼獲取LatLng - Google Maps API
回答
不能你只需要調用下面進行更換操作{}郵政編碼與郵遞區號或城市和州 http://maps.googleapis.com/maps/api/geocode/json?address= {}郵政編碼
這是一個帶鏈接如何使用JavaScript地理編碼:Geocode walk-thru。如果您需要特定的緯度/經度號碼的通話geometry.location.lat()或geometry.location.lng()(API for google.maps.LatLng class)
例子來獲得緯度/經度:
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);
我不小心在另一個線程中發佈了相同的答案,那麼它不會讓我發佈另一個3分鐘!哈哈 這將允許您用一個地址做: http://maps.googleapis.com/maps/api/geocode/xml?address=Mountain+View,+CA&sensor=false 返回將有
,如果我個子帶拉鍊的地址,這項工作也woudl? – Scott 2011-04-07 19:09:44
是的,這裏有一個可以測試的例子。文本框位於左上角。 http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html – Mark 2011-04-07 19:12:11
只是一個提示: 郵政編碼不是全球唯一的所以這是值得提供國家ISO代碼在請求(https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)。
e.g尋找拋光(ISO代碼PL
)郵政編碼01-210
的座標:
https://maps.googleapis.com/maps/api/geocode/json?address=01210,PL
如何獲取用戶的國家代碼?
如果您想基於IP地址有它的服務,例如,你可以做得到的要求,讓您的用戶國家簡介: http://ip-api.com/json
感謝您的提示,只是使用地址= 01210沒有提供正確的結果。與「,PL」加法它工作正常! – Havrin 2017-10-30 14:52:55
- 1. 從Google地圖獲取郵政編碼
- 2. Google Maps API郵政編碼邊界
- 3. 用於郵政編碼的Google Maps API
- 4. 使用Google Maps Javascript API獲取郵政編碼V3反向地理編碼
- 5. 如何使用Google Places API獲取郵政編碼?
- 6. 如何讓Google Maps「Places API」返回郵政編碼信息?
- 7. 使用codeigniter google-maps-api-v3-library的郵政編碼搜索
- 8. 用於郵政編碼搜索的Google Maps API區域參數
- 9. Google Maps API:返回郵政編碼結果
- 10. 對英國郵政編碼使用Google Maps API componentRestrictions嗎?
- 11. 從google api獲取郵編?
- 12. Google Maps API地理編碼郵政編碼並設置國家代碼?
- 13. 從5位數的郵政編碼,編程,api獲取9位數的郵政編碼
- 14. Google Maps API地理編碼 - 波蘭語地址沒有郵政編碼?
- 15. 從經緯度獲取郵政編碼
- 16. iOS中的郵政編碼獲得(null)Google Maps SDK反向地理編碼
- 17. 我可以從Google Maps API獲取一個國家/地區的所有郵政編碼嗎?
- 18. 如何從英國郵政編碼獲取地理位置
- 19. 如何使用Google Maps API查看各城市的郵政編碼?
- 20. Google Maps API地理編碼
- 21. Google地理編碼API返回盧森堡郵政編碼的錯誤/空值
- 22. 從JSON結果中獲取郵政編碼值
- 23. 郵政編碼
- 24. 截至2015年,有沒有辦法通過Google Maps API獲取意大利郵政編碼的界限?
- 25. 使用任何Google API獲取給定位置上的所有郵政編碼
- 26. 使用YQL獲取郵政編碼半徑中的郵政編碼
- 27. 獲取谷歌JSON之外的郵政編碼
- 28. Android:從手機取回郵政編碼
- 29. 你能通過facebook api獲取朋友的郵政編碼嗎?
- 30. 谷歌地圖API:獲取郵政編碼
是否有特定的語言你尋找你的例子是在? – Mark 2011-04-07 18:57:17
Javascript hopefully ... – Scott 2011-04-07 19:00:49