如何从选定的结果中获取纬度/经度
我有一个搜索字段,它使用 google place api 来自动建议位置,如下所示:
<input type="text" id="addressInput" name="addressInput" class="span3 search-query" placeholder="Enter location..">
<script>
var autocomplete = new google.maps.places.Autocomplete($("#addressInput")[0], {});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
console.log(place.address_components);
});
</script>
当用户输入地址或城市时,它会建议就好。但是一旦用户单击结果,我如何从用户那里检索所选选项的纬度和经度?
谷歌的例子似乎是根据放置标记来找到它们的。我根本没有在地图上显示任何内容。
I have a search field that uses the google places api to autosuggest locations like so:
<input type="text" id="addressInput" name="addressInput" class="span3 search-query" placeholder="Enter location..">
<script>
var autocomplete = new google.maps.places.Autocomplete($("#addressInput")[0], {});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
console.log(place.address_components);
});
</script>
As the user types an addrress or city, it suggests just fine. but once a user clicks on a result, how do I retrieve the lat and long of that selected option from the user?
The google examples seem to be find them based on dropping a marker. I'm not displaying anything on a map at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请查看以下内容:
http ://code.google.com/intl/pl-PL/apis/maps/documentation/javascript/geocoding.html#ReverseGeocoding
它包含大量信息 - 您会找到您需要的任何内容!
Please have a look at the following:
http://code.google.com/intl/pl-PL/apis/maps/documentation/javascript/geocoding.html#ReverseGeocoding
It contains loads of information - you will find anything you need!
以下内容应该可以回答您的问题:
https://developers.google.com/maps/文档/javascript/places#getting_place_information
The following should answer your question:
https://developers.google.com/maps/documentation/javascript/places#getting_place_information