我怎样才能以编程方式获取纬度,位置的经度或使用api [英] How can I get latitude, longitude of a location programmatically or using a api

查看:114
本文介绍了我怎样才能以编程方式获取纬度,位置的经度或使用api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从佛罗里达州这样的城市名称获得纬度,我怎样才能通过向Google地图API发送JSON请求来获取纬度和经度。

How can I get latitude from a city name like Florida how can I get the latitude and longitude from sending a JSON request to a Google map API.

任何方式来做到这一点?

Is there any way to do this?

我需要通过JSON在JavaScript或jQuery中的解决方案。

I need a solution in JavaScript or jQuery through JSON.

推荐答案

Not sure what you mean when you say send json but you can do it with this function:

函数getLatLong(地址){
var geo = new google.maps.Geocoder;

geo.geocode({'address':address},function(results,status){
if(status == google.maps.GeocoderStatus.OK){
return结果[0] .geometry.location;
} else {
alert(由于以下原因,Geocode不成功:+ status);
}

});

}

function getLatLong(address){ var geo = new google.maps.Geocoder; geo.geocode({'address':address},function(results, status){ if (status == google.maps.GeocoderStatus.OK) { return results[0].geometry.location; } else { alert("Geocode was not successful for the following reason: " + status); } }); }

会返回一个可以引用的对象.lat ()和.lng()来获取纬度和经度。

that will return an object which you can reference with .lat() and .lng() to get the latitude and longitude.

这篇关于我怎样才能以编程方式获取纬度,位置的经度或使用api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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