我想在地图中使用自定义标记(图像)。
目前我的代码如下:
<script>
function myMap() {
var mapCanvas = document.getElementById("map");
var mapOptions = {
center: new google.maps.LatLng(47.3921611, 8.4957963),
zoom: 14
}
var map = new google.maps.Map(mapCanvas, mapOptions);
}
</script>
如何将其实现到我的代码中?
答案 0 :(得分:1)
来自Google's "simple Marker" example:
var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png';
var beachMarker = new google.maps.Marker({
position: {lat: -33.890, lng: 151.274},
map: map,
icon: image
});
将代码段添加到您问题中的代码中:
function myMap() {
var mapCanvas = document.getElementById("map");
var mapOptions = {
center: new google.maps.LatLng(47.3921611, 8.4957963),
zoom: 14
}
var map = new google.maps.Map(mapCanvas, mapOptions);
var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png';
var beachMarker = new google.maps.Marker({
position: map.getCenter(),
map: map,
icon: image
});
}
google.maps.event.addDomListener(window, 'load', myMap);
&#13;
html,
body,
#map {
height: 100%;
width: 100%;
}
&#13;
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>
&#13;