如何将纬度/经度转换为地址

时间:2019-06-01 17:01:52

标签: javascript geolocation

我写了一些此代码有效的代码,但只能得到经度和纬度 但是我想从街道地址转换纬度和经度。

<!DOCTYPE html>
<html>

<head>
  <title>location</title>
</head>
<body>
  <script type="text/javascript">
    navigator.geolocation.getCurrentPosition(function(position) {
      document.write("latitude= " + position.coords.latitude);
      document.write("longitude= " + position.coords.longitude);
    });
  </script>
</body>

</html>

2 个答案:

答案 0 :(得分:0)

尝试使用此功能进行Google反向地理编码:

Reverse geocoding Example

答案 1 :(得分:0)

如果您想从某个地址获取经度和纬度,则该过程称为地理编码,可以使用Google Maps API完成。这是运行此转换的示例python代码:

import requests
import json

def convert(address):
    URL = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&key=[INSERT API KEY]&callback=initMap'
    r = requests.get(URL).json()
    return r['results'][0]['geometry']['location']

如果相反,您想根据纬度和经度来获取地址,则也可以通过Google Maps API进行反向地理编码。

相关问题