鉴于纬度和经度,我们如何使用Javascript或Python将其转换为街道地址?
答案 0 :(得分:17)
99%的时间,大多数人将您链接到Google地图的API。答案不错。但是 - 请注意禁止使用,使用限制和Terms of Use!虽然分布式应用程序很多都不会违反使用限制,但对于Web应用程序来说却是非常有限的。 TOS不允许您将Google的数据重新用于带有您皮肤的应用程序。你不愿意让你的商业计划因谷歌的停止和终止信而脱轨,不是吗?
一切都不会丢失。有几个公开的数据来源,包括美国政府消息来源。以下是一些最好的:
美国人口普查Tiger Database特别支持反向地理编码,并且对美国地址免费开放。大多数其他数据库都来自美国。
维基百科模型中的用户支持答案 1 :(得分:5)
您可以使用Google Maps API。它有一个API函数可以完成这个: http://code.google.com/intl/da-DK/apis/maps/documentation/javascript/services.html#ReverseGeocoding
答案 2 :(得分:5)
您可以尝试https://mapzen.com/pelias它的开源并积极开发。
例如:http://pelias.mapzen.com/reverse?lat=40.773656&lon=-73.9596353
返回(格式化后):
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{
"id":"address-node-2723963885",
"type":"osmnode",
"layer":"osmnode",
"name":"151 East 77th Street",
"alpha3":"USA",
"admin0":"United States",
"admin1":"New York",
"admin1_abbr":"NY",
"admin2":"New York",
"local_admin":"Manhattan",
"locality":"New York",
"neighborhood":"Upper East Side",
"text":"151 East 77th Street, Manhattan, NY"
},
"geometry":{
"type":"Point",
"coordinates":[-73.9596265, 40.7736566]
}
}
],
"bbox":[-73.9596265, 40.7736566, -73.9596265, 40.7736566],
"date":1420779851926
}
答案 3 :(得分:1)
您可以使用Google Geo API。有关API V3的示例代码,请参见my blog
<HEAD>
<TITLE>Convert Latitude and Longitude (Coordinates) to an Address Using Google Geocoding API V3 (Javascript)</TITLE>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var address = new Array();
/*
* Get the json file from Google Geo
*/
function Convert_LatLng_To_Address(lat, lng, callback) {
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&sensor=false";
jQuery.getJSON(url, function (json) {
Create_Address(json, callback);
});
}
/*
* Create an address out of the json
*/
function Create_Address(json, callback) {
if (!check_status(json)) // If the json file's status is not ok, then return
return 0;
address['country'] = google_getCountry(json);
address['province'] = google_getProvince(json);
address['city'] = google_getCity(json);
address['street'] = google_getStreet(json);
address['postal_code'] = google_getPostalCode(json);
address['country_code'] = google_getCountryCode(json);
address['formatted_address'] = google_getAddress(json);
callback();
}
/*
* Check if the json data from Google Geo is valid
*/
function check_status(json) {
if (json["status"] == "OK") return true;
return false;
}
/*
* Given Google Geocode json, return the value in the specified element of the array
*/
function google_getCountry(json) {
return Find_Long_Name_Given_Type("country", json["results"][0]["address_components"], false);
}
function google_getProvince(json) {
return Find_Long_Name_Given_Type("administrative_area_level_1", json["results"][0]["address_components"], true);
}
function google_getCity(json) {
return Find_Long_Name_Given_Type("locality", json["results"][0]["address_components"], false);
}
function google_getStreet(json) {
return Find_Long_Name_Given_Type("street_number", json["results"][0]["address_components"], false) + ' ' + Find_Long_Name_Given_Type("route", json["results"][0]["address_components"], false);
}
function google_getPostalCode(json) {
return Find_Long_Name_Given_Type("postal_code", json["results"][0]["address_components"], false);
}
function google_getCountryCode(json) {
return Find_Long_Name_Given_Type("country", json["results"][0]["address_components"], true);
}
function google_getAddress(json) {
return json["results"][0]["formatted_address"];
}
/*
* Searching in Google Geo json, return the long name given the type.
* (if short_name is true, return short name)
*/
function Find_Long_Name_Given_Type(t, a, short_name) {
var key;
for (key in a ) {
if ((a[key]["types"]).indexOf(t) != -1) {
if (short_name)
return a[key]["short_name"];
return a[key]["long_name"];
}
}
}
</SCRIPT>
</HEAD>
答案 4 :(得分:1)
var geocoder = new google.maps.Geocoder(); // create a geocoder object
var location = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); // turn coordinates into an object
geocoder.geocode({'latLng': location}, function (results, status) {
if(status == google.maps.GeocoderStatus.OK) { // if geocode success
var add=results[0].formatted_address; // if address found, pass to processing function
document.write(add);