google-maps - 从 Google 地图 URL 获取我的 JSON 的坐标
问题描述
我需要为我的 JSON 从 Google 地图 URL 获取坐标。我从 URL 获取 lat、lng 和 zoom。但是我的标记与谷歌地图标记的位置不同。例如这里: https ://www.google.com/maps/place/ADRA+Laos/@17.8575854,102.1769446,8.81z/data=!4m5!3m4!1s0x3124662d079f33c5:0xcef5f2b499df9a6e!8m2!3d17.9613965!4d102.3 我拿 lat: 17.8575854, lng: 102.1769446, zoom: 8.81
我想我错过了一些我必须接受的东西。我的标记与原始标记相差不远,但不在同一个位置。请告诉我我错过了什么
解决方案
@ 符号后的坐标是地图的中心,而不是地点的坐标。地点/标记的坐标位于 URL 的末尾:!8m2!3d17.9613965!4d102.6307923
17.9613965,102.6307923
代码片段:
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 17.9613965, lng: 102.6307923},
zoom: 18
});
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map
})
}
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap" async defer></script>
推荐阅读
- javascript - 从 API 获取并放入一个数组
- python - Flask/Jinja2 继续声明
- c++ - 如何在 C++ 中对方法的副作用进行单元测试?
- python - 如何使用 micropython 控制插入 BBC microbit 的水泵的速度
- python - 在类和线程过程中使用烧瓶
- c# - C#为什么使用CreateFileAsync方法时没有GetAwaiter(StorageFile)的实现?
- javascript - 无法读取未定义的属性“组件” - 反应组件插件的 webpack 构建
- json - 如何使用 jq 过滤带有小 JSON 的大 JSON?
- python - Django - 模型结构
- c# - SymbolFinder.FindReferencesAsync 没有返回所有结果?