【问题标题】:Google Maps API not returning latitude or longitude and autocomplete not workingGoogle Maps API 未返回纬度或经度且自动完成功能不起作用
【发布时间】:2017-01-30 07:11:53
【问题描述】:

我想使用 JavaScript 获取某个位置的坐标。但是我的自动完成有问题。我遇到了一个类似的查询,但没有一个解决方案可以帮助我。

我的代码:

<html>
<head>
<title>Geocoding</title>
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script type="text/javascript">
    google.maps.event.addDomListener(window, 'load', initilize);
    function initilize() {
        var autocomplete = new google.maps.places.Autocomplete(document.getElementById('txtautocomplete'));
        google.maps.events.AddListener(autocomplete, 'place_changed', function () {
            var places = autocomplete.getPlace();
            var location = "<b>Location:</b>" + places.formatted_address + "<br/>";
            location += "<b>Latitude:</b>" + places.geometry.location.lat + "<br/>";
            location += "<b>Longitude:</b>" + places.geometry.location.lng + "<br/>";
            document.getElementById('lblresult').innerHTML = location;
        });

    };
</script>
location:<input type="text" id="autocomplete" placeholder="Enter the address"/> <br/> <br/>
<label id="lblresult"></label>

【问题讨论】:

标签: javascript html api model-view-controller


【解决方案1】:

试着看看这个问题的第一个答案: Google map api get Latitude and longitude from autocomplete without map

它似乎也可以解决您的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    相关资源
    最近更新 更多