我使用谷歌地理编码为经纬度和我的问题是,有没有办法可以找到经纬度的邮政编码?纬度和经度可以找到邮政编码?
回答
我想你正在寻找的是results
数组中的address_components[]
。也许这样的事情会起作用,只需要输入下面的内容,这样可能会有错误,但我认为你会明白。
http://code.google.com/apis/maps/documentation/geocoding/#Results
function (request, response) {
geocoder.geocode({ 'address': request.term, 'latLng': centLatLng, 'region': 'US' }, function (results, status) {
response($.map(results, function (item) {
return {
item.address_components.postal_code;//This is what you want to look at
}
}
请注意下面的答案以获得最新的答案(显然API自这个答案以来没有改变2013):http://stackoverflow.com/a/17933106/4526479 –
雅虎PlaceFinder API提供了良好的笏由纬度/经度查找位置数据:
http://developer.yahoo.com/geo/placefinder/
这里的,他们用一个例子网址:
http://where.yahooapis.com/geocode?q=38.898717,+-77.035974&gflags=R
看起来是这样:
解析是将地址(如“1600 剧场百汇,山景,CA”)转换为地理坐标 (如纬度37.423021和经度-122.083739),您可以使用 放置标记或位置的过程地图。 Google地理编码API 提供了一种通过HTTP请求访问地理编码器的直接方式。 此外,该服务允许您执行逆向操作 (将坐标转换为地址);这个过程被称为 “反向地理编码”。
你也应该看看这个文档其中有一些示例代码: Reverse Geocoding
yoda:我将地址转换为你张贴在上面,但我的问题是更多“是否有一种方法,我可以得到基于经纬度的邮政编码 –
这里是我的解决方案,它跳过谷歌js和得到的结果JSON(jQuery的&的CoffeeScript):
navigator.geolocation.getCurrentPosition (pos) ->
coords = pos.coords
url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{ coords.latitude },#{ coords.longitude }&sensor=true&callback=zipmap"
$.ajax({
url: url,
dataType: 'json',
cache: true,
}).success (data) ->
for c in data.results[0].address_components
if c.types[0] == 'postal_code'
alert c.short_name
https://developers.google.com/maps/documentation/geocoding/
我想这没有工作很长一段时间 - 尽管我发誓一点。我必须错过一些秘密握手,这是Google .js的一部分。我切换到使用OpenStreetMap.org:
getZip = (cb) ->
# try to populate zip from geolocation/google geocode api
if document.location.protocol == 'http:' && navigator.geolocation?
navigator.geolocation.getCurrentPosition (pos) ->
coords = pos.coords
url = "http://nominatim.openstreetmap.org/reverse?format=json&lat=#{ coords.latitude }&lon=#{ coords.longitude }&addressdetails=1"
$.ajax({
url: url,
dataType: 'jsonp',
jsonp: 'json_callback',
cache: true,
}).success (data) ->
cb(data.address.postcode)
以下是编译的JavaScript:
getZip = function(cb) {
if (document.location.protocol === 'http:' && (navigator.geolocation != null)) {
return navigator.geolocation.getCurrentPosition(function(pos) {
var coords, url;
coords = pos.coords;
url = "http://nominatim.openstreetmap.org/reverse?format=json&lat=" + coords.latitude + "&lon=" + coords.longitude + "&addressdetails=1";
return $.ajax({
url: url,
dataType: 'jsonp',
jsonp: 'json_callback',
cache: true
}).success(function(data) {
return cb(data.address.postcode);
});
});
}
};
使用方法如下:
getZip(function(zipcode){ console.log("zip code found:" + zipcode); });
这是很好的注意,谷歌地图有新版本时,因为介绍了这一解决方案。
参考:https://developers.google.com/maps/documentation/geocoding/?csw=1#ReverseGeocoding
下面是谷歌地图3.0版更新的例子。它使用JIssak上面提到的地址组件。我应该注意到没有倒退。如果它找不到邮政编码,它什么也不做。这对您的脚本来说可能很重要,也可能不重要。
var latlng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
for (j = 0; j < results[0].address_components.length; j++) {
if (results[0].address_components[j].types[0] == 'postal_code')
alert("Zip Code: " + results[0].address_components[j].short_name);
}
}
} else {
alert("Geocoder failed due to: " + status);
}
});
- 1. 经度/纬度到邮政编码?
- 2. 从经纬度查找邮政编码
- 3. 通过Java中的邮政编码查找纬度和经度
- 4. 英国邮政编码的地理编码经度和纬度?
- 5. 得到纬度和经度使用邮政编码
- 6. 从经度和纬度没有得到邮政编码
- 7. 从经纬度获取邮政编码
- 8. iOS从邮政编码查找位置(经度,纬度)
- 9. 从纬度和经度获取一个邮政编码
- 10. 从经度和纬度坐标获取邮政编码
- 11. 从javascript中的纬度和经度获取邮政编码
- 12. 使用PHP获取邮政编码的经度和纬度
- 13. 谷歌地图从邮政编码获取经度和纬度
- 14. 如何获取邮政编码的经度和纬度?
- 15. 基于邮政编码的经度和纬度
- 16. Perl得到的位置(经度+纬度),加上邮政编码
- 17. android从印度经纬度获得印度的邮政编码
- 18. 如何查找英国的纬度和经度的邮政编码
- 19. 查找最接近的邮政编码,经纬度在MySQL
- 20. 如何查找经纬度对应的邮政编码
- 21. 寻找基于邮政编码的经纬度
- 22. 从经度,纬度获取邮政编码?
- 23. 从经度/纬度获取邮政编码
- 24. 从邮政编码获取经度/纬度
- 25. SimpleGeo是否提供邮政编码给纬度/经度映射?
- 26. 获取纬度/经度附近的邮政编码列表
- 27. 得到一个地方的经度和纬度针对其邮政编码
- 28. 获得纬度和经度给出邮政编码和/或地址字符串
- 29. 谷歌地图:从地理编码的邮政编码获取纬度/经度
- 30. 需要找到经度和纬度的邮政编码和存储到我的数据库
请注意,此问题的接受答案已经过时。有一个解决方案可以解决当前版本的Google Maps API,它自2013年起显然没有改变,在这里:http://stackoverflow.com/a/17933106/4526479 –