javascript 将纬度/经度转换为地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17603738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert Latitude/Longitude To Address
提问by user2574350
I need to convert a lat/long coordinates to a address. I could use the Google Maps API but I would need a XML Response.
I have looked at Convert Lat Long to address Google Maps ApiV2but I need to be able to do this in JavaScript.
My Question is: How To Convert a Lat/Long coordinate to an address?
我需要将纬度/经度坐标转换为地址。我可以使用 Google Maps API,但我需要一个 XML 响应。我已经查看了Convert Lat Long 以解决 Google Maps ApiV2,但我需要能够在 JavaScript 中做到这一点。
我的问题是:如何将纬度/经度坐标转换为地址?
采纳答案by Jeroen Vannevel
You can use GeoNames' FindNearestAddress.
您可以使用 GeoNames 的FindNearestAddress。
It takes a latitude and longitude parameter and returns the nearest address in XML format.
它接受一个纬度和经度参数,并以 XML 格式返回最近的地址。
From the example:
从示例中:
http://api.geonames.org/findNearestAddress?lat=37.451&lng=-122.18&username=demo
<address>
<street>Roble Ave</street>
<mtfcc>S1400</mtfcc>
<streetNumber>649</streetNumber>
<lat>37.45127</lat>
<lng>-122.18032</lng>
<distance>0.04</distance>
<postalcode>94025</postalcode>
<placename>Menlo Park</placename>
<adminCode2>081</adminCode2>
<adminName2>San Mateo</adminName2>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<countryCode>US</countryCode>
</address>
</geonames>
回答by Thamaraiselvam
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);
source from https://gist.github.com/marchawkins/9406213/download#it works me
来自https://gist.github.com/marchawkins/9406213/download# 的来源 它对我有用
回答by Jobin Philip
this is an alternate method. U can use the following google api for getting the address as json script .You can parse the same in your application to get the address.
这是一种替代方法。您可以使用以下 google api 作为 json 脚本获取地址。您可以在应用程序中解析相同的内容以获取地址。