undefined Lat和Long谷歌地图

时间:2015-10-21 10:20:17

标签: javascript google-maps

我想要lat和long坐标。而不是协调我得到这个

位置: Waalre,荷兰 地址:荷兰Waalre 纬度:未定义 经度:未定义

        

    <script type="text/javascript">
    google.maps.event.addDomListener(window, 'load', intilize);
    function intilize() {
        var autocomplete = new google.maps.places.Autocomplete(document.getElementById("txtautocomplete"));

        google.maps.event.addListener(autocomplete, 'place_changed', function () {

        var place = autocomplete.getPlace();
        var location = "Address: " + place.formatted_address + "<br/>";
        location += "Latitude: " + place.geometry.location.A + "<br/>";
        location += "Longitude: " + place.geometry.location.F;
        document.getElementById('lblresult').innerHTML = location
        });

    };

    </script>

    <span>location:</span><input type="text" id="txtautocomplete" style="width:200px" placeholder="enter the adress"/>
    <label id="lblresult"></label>
</body>

2 个答案:

答案 0 :(得分:3)

伙伴,

无法访问

.geometry.location.A / .geometry.location.F,请使用lat()和lng()

改为:

    location += "Latitude: " + place.geometry.location.lat() + "<br/>";
    location += "Longitude: " + place.geometry.location.lng();

答案 1 :(得分:0)

问题已解决。

而不是&#34; place.geometry.location.A&#34;它必须是&#34; place.geometry.location.lat()&#34; 和 &#34; place.geometry.location.F&#34;它必须是&#34; place.geometry.location.lng()&#34;