javascript - 将纬度和经度值转换为地名并显示?
问题描述
有没有办法将纬度和经度值转换为地名,然后能够在 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");
}
代码可以返回经纬度并显示出来,如果可能的话,我想获取具体的地方,然后显示在页面上还是记录在表格中?
解决方案
基本上,你需要三样东西:
带有坐标的地点列表。这有点超出了本网站的范围。
距离函数。您可以为此使用余弦规则或半正弦规则。
比 O(n) 更好的最近邻算法。为此,您可以例如将您的集合从 1 分区,为此,谷歌“球体三角形镶嵌”,然后您可以优化您的最近邻算法。
推荐阅读
- flutter - 我们如何在 appbar flutter 中使用两行就像第一行带有标题,第二行带有搜索输入字段
- python - AsyncIOMotorCommandCursor.fetch_next 是否会阻止可重试读取?
- python - 有没有办法在 Discord.py 上直接向某人发送消息?
- bash - 如何在 WSL2 shell 脚本中使用 Windows 用户名?
- sql - Postgres:合并具有相同ID的记录
- kotlin - Kotlin 在我使用 I do Any as Int 时显示错误
我想比较 JSONObject 的字段。
这是我正在尝试的代码:
x = JSONObject() x.put("num",1) if(x["num"] as Int < 2){ print("Good work!") }
- javascript - 在新的浏览器选项卡中自动打开下载的功能
- c# - 我不能让我的测验每个项目只弹出一次
- jquery - jQuery渲染html文档时如何获取js文件中的dom元素?
- html - Material-ui 4.11.4 - 网格:列中的项目需要容器方向='行'才能正确显示(??)