通过谷歌地图地理代码的jquery / ajax从经度/纬度获取城市/州? [英] Get City/State from Latitude/Longitude via jquery/ajax with google maps geocode?

查看:121
本文介绍了通过谷歌地图地理代码的jquery / ajax从经度/纬度获取城市/州?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了这个概念的一些jscript / jquery实现,在这里你可以输入一个邮政编码并从谷歌地图api中获得一个长/纬度。然而,就我而言,我已经有了一组坐标,并且想知道当我们提供它时,是否可以从API动态获取文本City,State的结果通过jquery的长/纬度?



谢谢!

解决方案

是一个名为反向地理编码的过程,而且Google有相当丰富的文档。



举例如下:

  $。ajax({url:'http:/ /maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true',
成功:函数(数据){
alert(data.results [0 ] .formatted_address);
/ *或者你可以遍历城市和州的组件* /
}
});


I've seen a few jscript/jquery implementations of this concept in reverse, where you can enter a zip code and get a long/lat from the google maps api.

However, in my case, I already have a set of coordinates and was wondering if its possible to dynamically get a textual City, State result from the API when we feed it the long/latitude via jquery?

Thanks!

解决方案

This is a process called reverse geocoding, and Google have quite extensive documentation on it.

An example would be:

$.ajax({ url:'http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true',
         success: function(data){
             alert(data.results[0].formatted_address);
             /*or you could iterate the components for only the city and state*/
         }
});

这篇关于通过谷歌地图地理代码的jquery / ajax从经度/纬度获取城市/州?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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