串接地图 JavaScript API 中虽然相较起来难度较高,不过官方文件写的也很简单易懂。
1.宣告 HTML5 文件,将 JS CDN 引入档案(要先申请金钥)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>google maps api</title>
<script async
src="https://maps.googleapis.com/maps/api/js?key=你的金钥&callback=initMap">
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
2.设定 map 容器的高度为100%,否则会看不到内容
<style>
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script>
let map;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
// 中心点位置
center: { lat: 23.197250366210938, lng: 119.42967987060547 },
zoom: 18, // 地图缩放比例 (0-20)
maxZoom: 20, // 使用者能缩放地图的最大比例
minZoom: 3, // 使用者能缩放地图的最小比例
streetViewControl: false, // 是否显示右下角街景小人
mapTypeControl: false // 使用者能否切换地图样式:一般、卫星图等
});
}
</script>
参考来源:https://developers.google.com/maps/documentation/javascript/overview#maps_map_simple-html
<<: [Day??] 2021 iThome 铁人赛 - 颁奖典礼 @ 2022.01.08‧辅仁大学
>>: 免费Youtube影片下载工具全推荐!只要加上文字就能下载
前言 (因为最近时间有点少XD,所以偷偷选了比较短的影片来硬塞XD) 这篇显然就是个蛮一般的top...
tags: 2021铁人赛 React 投资Dashboard内容设计 要实际动手制作wirefra...
今天要介绍的Decorator Pattern,跟昨天的Composite Pattern都是属...
大家好!本篇将会以我转职的心路历程作为主轴,我为什麽转职成QA?当开发与当QA差很多吗?当QA该注意...
一. 前言 在如今社群网路蓬勃的时代,从网路充斥着许多文字资料,要如何有效的分析文字让电脑可以知道我...