是否可以使用谷歌地图从坐标获取地址? [英] Is it possible to get an address from coordinates using google maps?

查看:108
本文介绍了是否可以使用谷歌地图从坐标获取地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是好奇。也许对于未来的项目。我想知道是否可以通过Google API从给定坐标中检索地址。

解决方案

是的。只需使用Google地理编码和Places API https://developers.google.com/maps/documentation/geocoding / https://developers.google.com/maps/documentation/places/



示例(源自):

  var geocoder; 

函数initialize(){
geocoder = new google.maps.Geocoder();
}

函数codeLatLng(lat,lng){
var latlng = new google.maps.LatLng(lat,lng);
geocoder.geocode {(
'latLng':latlng
},function(results,status){
if(status === google.maps.GeocoderStatus.OK){
if(results [1]){
console.log(results [1]);
} else {
alert('找不到结果');
}
} else {
alert('Geocoder failed because:'+ status);
}
});
}

google.maps.event.addDomListener(window,'load',initialize);


I'm just curious. Maybe for a future project. I want to know if it's possible to retrieve an address from a giving coordinate via the Google API.

yes. Just use Google Geocoding and Places API https://developers.google.com/maps/documentation/geocoding/ and https://developers.google.com/maps/documentation/places/

Example (derived from here):

var geocoder;

function initialize() {
  geocoder = new google.maps.Geocoder();
}

function codeLatLng(lat, lng) {
  var latlng = new google.maps.LatLng(lat, lng);
  geocoder.geocode({
    'latLng': latlng
  }, function (results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        console.log(results[1]);
      } else {
        alert('No results found');
      }
    } else {
      alert('Geocoder failed due to: ' + status);
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

这篇关于是否可以使用谷歌地图从坐标获取地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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