【问题标题】:Convert Latitude and Longitude values to a place name and display it?将纬度和经度值转换为地名并显示?
【发布时间】:2020-08-04 11:42:54
【问题描述】:

有没有办法将纬度和经度值转换为地名,然后能够在 HTML 页面上显示该地名?

if ('geolocation' in navigator) {
  let watchID = navigator.geolocation.watchPosition(position => {
    let latitude = position.coords.latitude;
    let longitude = position.coords.longitude;
    console.log(latitude, longitude);
  }, error => {
    console.log(error.code);
  }, {
    enableHighAccuracy: true
  });
  console.log(watchID);
} else {
  console.log("Not Supported");
}

代码可以返回经纬度并显示出来,如果可能的话我想获取具体的地方显示在页面上还是记录在表格中?

【问题讨论】:

标签: javascript jquery geolocation


【解决方案1】:

基本上,你需要三样东西:

  1. 带有坐标的地点列表。这有点超出了本网站的范围。

  2. 距离函数。为此,您可以使用余弦规则或半正弦规则。

  3. 比 O(n) 更好的最近邻算法。为此,您可以例如从 1 开始划分你的集合,为此谷歌“球体三角形镶嵌”,然后你可以优化你的最近邻算法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多