如何使用 Google Maps V3 从 lat/lng 获取城市?

Posted

技术标签:

【中文标题】如何使用 Google Maps V3 从 lat/lng 获取城市?【英文标题】:How to get city from lat/lng with Google Maps V3? 【发布时间】:2012-04-04 14:55:54 【问题描述】:

这是what 我已经完成了:

var geocoder = new google.maps.Geocoder();
var location = new google.maps.LatLng(45.930976,10.639744);

geocoder.geocode( 'latLng': location  , function(results, status) 
    if (status == google.maps.GeocoderStatus.OK) 
        alert(results[1].address_components[0].long_name);
    
); 

但我不想使用 address_components[i] 哪个参数,因为每个请求可能会有所不同。获取城市的参数如何? (或位置,或国家,等等......)。

【问题讨论】:

你有没有得到这个工作?我很想知道解决方案是什么。 【参考方案1】:

不确定我是否正确阅读 API (Geocoding API doc),但它看起来可能是 'types:locality'

【讨论】:

你解决过这个问题吗?我很想知道如果你这样做了。

以上是关于如何使用 Google Maps V3 从 lat/lng 获取城市?的主要内容,如果未能解决你的问题,请参考以下文章

如何从 Google Maps v3 API 中删除带有 mysql 数据的标记?

如何在 Google Maps V3 上触发标记的 onclick 事件?

如何在 Google Maps V3 中永久显示标记的标签/标题?

Google Maps API v3:如何将缩放级别和地图中心设置为用户提交的位置?

Google Maps Api v3 - 如何删除集群图标?

如何将 Google Maps plus 代码转换为 Lng 和 Lat 坐标