javascript - 谷歌地图地理编码 API 返回不正确的纬度/经度键

标签 javascript google-maps google-maps-api-3

我正在使用 Google Maps JavaScript API v3

以下代码几乎直接来自谷歌示例代码,但我遇到了一个奇怪的问题。 results[0].geometry.location 具有键“k”和“D”而不是“lat”和“lng”。

知道为什么会这样吗?

    mapui.geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            console.log(results[0]);
            var lat = results[0].geometry.location['lat'];
            var lng = results[0].geometry.location['lng'];
        }
    })

notice the keys in locations

最佳答案

您必须使用 lat()lng() 函数。 geometry.location 是一个 LatLng 类。

var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();

https://developers.google.com/maps/documentation/javascript/reference#GeocoderGeometry https://developers.google.com/maps/documentation/javascript/reference#LatLng

在您的 javascript 控制台中查看 __proto__,您将找到可用的方法。

关于javascript - 谷歌地图地理编码 API 返回不正确的纬度/经度键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27520224/

相关文章:

android - 在谷歌地图上扩展覆盖标记?

android - 适用于 Android 的自定义 Google map 样式

javascript - 为什么我的导航器不工作?

javascript - 我们可以用 `name ` 设置属性而不是 `class` 或 `id`

android - 将遗留 MapsV2 Eclipse 应用程序更新到最新的 API

java - 在 android 中使用 Google map api v2 显示我的轨迹

javascript - map API v3 : detect Ctrl+click on a marker

java - 在 javaFXML 文件中键入以使用 GmapsFX

javascript - JQuery .click() 不工作可能会干扰 angularJS

javascript - 使用 url 标签滚动到特定 div