如何以编程方式或使用 api 获取位置的纬度、经度 [英] How can I get latitude, longitude of a location programmatically or using a api
本文介绍了如何以编程方式或使用 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.
推荐答案
不知道你说的 send json 是什么意思,但你可以用这个函数来做:
Not sure what you mean when you say send json but you can do it with this function:
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屋!
查看全文