如何将可嵌入的 Google 地图导出到等效的 Map API JavaScript 代码中
How to Export a Embedable Google Map into the equivalent Map API JavaScript code
嵌入式地图和Google Maps JavaScript API是创建自定义地图的两种方法:https://developers.google.com/maps/web/
我有一个非程序员,他在没有任何JavaScript的情况下创建了一个嵌入式地图。他的HTML代码是这样的:
<iframe class="maps-frame" src="//www.google.com/maps/embed/v1/place?q=Harrods,Brompton%20Rd,%20UK&zoom=17&key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI"> </iframe>
但是,我们需要在地图上添加一些更多的自定义图形,这只能通过JavaScript API实现。问题是似乎不可能在 JS 的现有嵌入式映射上运行。 那么,是否有可能将嵌入式地图转换为产生相同效果的等效 JavaScript 代码呢?然后我可以获取这个生成的 JS 代码并添加更多 JS 代码以进行进一步的自定义。嵌入式地图包含许多使用 Google 的交互式工具创建的标记和多边形。我讨厌在JS中手动编码坐标来创建这些多边形。因此问题来了。
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644}, // put your data here
zoom: 8
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
async defer></script>
</body>
</html>
在 https://developers.google.com/maps/documentation/javascript/examples/map-simple 查找演示或按照文档操作:https://developers.google.com/maps/documentation/javascript/tutorial
相关文章:
- 回调函数中传递参数的困难(Google Map API Markers)
- 没有显示带有Infobox PHP/SQL的Google Map API v3
- 在javascript函数中访问Google map api
- Google Map API BackBoneJS 无法读取 null 的属性 'offsetWidth'
- Google MAP API 未捕获类型错误:无法读取 null 的属性“offsetWidth”
- 样式化地图和地点库Google Map API v3
- 在Google Map API中定位画布外的输入字段
- Google Map API v3 在 Wordpress 中不起作用
- Google Map API use LatLng or Address
- Google Map API - foreach 循环中的信息窗口
- 如何访问 Google Map API v3 的 getarray() 返回的数组
- 使用 js 将 JSON 文件加载到 bing map API 中
- 如何将可嵌入的 Google 地图导出到等效的 Map API JavaScript 代码中
- 带有PHP和Javascript的Google MAP API
- Google Map API v3 in Show in Emulator
- 在多边形中添加一些区域 [JavaScript:: Google Map API v3]
- AngularJS modal with google map API
- 将自定义地图标记图标添加到Google map API
- 如何使用event.addListener和Google Map API v3
- Google Map API下拉菜单Onchange事件侦听器