【发布时间】:2016-11-21 13:24:59
【问题描述】:
我的学校任务是首先创建一个移动网站原型(因此不是应用程序)。 我想在网站中集成谷歌地图 - , I've already put ground overlay in it,但我也想启用“我的位置层”。但是,当我尝试在代码中插入 mMap.setMyLocationEnabled(true); 时,我的位置按钮没有出现。
代码如下:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#map {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script type="text/javascript">
var historicalOverlay;
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 17,
center: {lat: 55.380, lng: 10.342652}
});
var imageBounds = {
north: 55.384621,
south: 55.376012,
east: 10.3473,
west: 10.333567
};
historicalOverlay = new google.maps.GroundOverlay(
'map2.svg',
imageBounds);
historicalOverlay.setMap(map);
}
mMap.setMyLocationEnabled(true);
</script>
</head>
<body>
</body>
</html>
<div id="map"></div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDbO6MrlSuKnLv7Q2bmDHYERx4t3_zHrAM&callback=initMap">
</script>
【问题讨论】:
-
您将 Google 地图 Javascript 代码与 Android/Java 代码混合在一起。在这里查看答案:stackoverflow.com/questions/24952593/…
标签: javascript html google-maps location maps