通过Google自动填充API获取基于地理位置名称的经纬度 [英] Get latitude and longitude based on location name with Google Autocomplete API

查看:121
本文介绍了通过Google自动填充API获取基于地理位置名称的经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的页面中有一个文本框,其中包含文本 getLat& Long 的位置名称和按钮。现在点击我的按钮,我必须在文本框中显示位置的纬度经度的提示。您可以使用 /documentation/javascript/services.html#Geocodingrel =noreferrer> Google Geocoder服务位于 Google Maps API 将您的位置名称转换为经度和纬度。因此,您需要一些代码:

  var geocoder = new google.maps.Geocoder(); 
var address = document.getElementById(address)。value;
geocoder.geocode({'address':address},function(results,status){
if(status == google.maps.GeocoderStatus.OK)
{
/ /对地理编码结果做些什么
//
// results [0] .geometry.location.latitude
// results [0] .geometry.location.longitude
}
});

更新

您是否包含v3 javascript API?

 < script type =text / javascript
src = http://maps.google.com/maps/api/js?sensor=set_to_true_or_false\">
< / script>


I have a textbox in my page which gets a location name and button with text getLat&Long. Now on clicking my button I have to show an alert of latitude and longitude of the location in the textbox. Any suggestion?

解决方案

You can use the Google Geocoder service in the Google Maps API to convert from your location name to a latitude and longitude. So you need some code like:

var geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK)
  {
      // do something with the geocoded result
      //
      // results[0].geometry.location.latitude
      // results[0].geometry.location.longitude
  }
});

Update

Are you including the v3 javascript API?

<script type="text/javascript"
     src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false">
</script> 

这篇关于通过Google自动填充API获取基于地理位置名称的经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆