javascript - Google map 地理编码成功,但未找到纬度

标签 javascript google-maps visual-studio-2013

这是我的异常(exception):

enter image description here 当我点击break并将鼠标悬停在值c上时,它是OK并且值B具有值:

enter image description here

这是我的 javascript:

var geocoder;
var map;

function codeAddress() {
    var address = document.getElementById("address").value;
    geocoder = new google.maps.Geocoder();

    geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            //console.log(results);
            //console.log("Lat: " + results[0].geometry.location.coords.latitude);
            //console.log("Lng: " + results[0].geometry.location.coords.longitude);
            return results[0].geometry.location;
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}

所以有一个结果并且它被填满了,但它并没有太长。 我用于测试的地址是:1600 Amphitheatre Parkway, Mountain View, CA 基于https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests但这不仅仅适用于这个地址。

我真的不知道。它几乎是示例代码的精确副本。

编辑 jsFiddle http://jsfiddle.net/7tvv71hs/

最佳答案

lat() 和 lng() 是函数而不是属性。 只需调用他们即可。

引用:

  1. Official Documentation

  2. similar question

关于javascript - Google map 地理编码成功,但未找到纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32607856/

相关文章:

javascript - 如何根据用户输入的日期订购餐 table

javascript - MarkerWithLabel 缩放时移动

android - 如何使用 Kotlin 在谷歌地图上添加标记?

javascript - JS : set address elements to proper values without clicking autocomplete

ios - 使用 Google-Maps-iOS-SDK (1.8.1) 时架构 armv7 的 undefined symbol

visual-studio - Visual Studio 警告 : “Some of the properties associated with the solution could not be read”

c# - 未安装 .NET 4.5.2 的目标包

具有混合值类型的 JavaScript 数组排序 - 寻找合适的比较函数

javascript - Backbone 中的 FileReader 范围问题

visual-studio-2013 - Microsoft.Web.Publishing.targets 在哪里?