【发布时间】: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