function initialize() {
var latlng = new google.maps.LatLng(47.605, -122.333);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var bounds = new google.maps.LatLngBounds();
var marker = new google.maps.Marker({
map: map,
position: latlng,
label: "0",
icon: pinSymbol('red')
});
bounds.extend(marker.getPosition());
var marker1 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(47.5, -122.0),
label: "A",
icon: pinSymbol('#00FF00')
});
bounds.extend(marker1.getPosition());
var marker2 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(47.6, -122.2),
label: "B",
icon: pinSymbol('orange')
});
bounds.extend(marker2.getPosition());
var marker3 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(47.7, -122.1),
label: "C",
icon: pinSymbol('yellow')
});
bounds.extend(marker3.getPosition());
map.fitBounds(bounds);
}
function pinSymbol(color) {
return {
path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z',
fillColor: color,
fillOpacity: 1,
strokeColor: '#000',
strokeWeight: 1,
scale: 1,
labelOrigin: new google.maps.Point(0, -29)
};
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
什麼是你的標誌是什麼樣子?你可以指定[SVG符號](https://developers.google.com/maps/documentation/javascript/symbols) – geocodezip
的顏色來表示沒有顏色屬性的標記。它們只給出'strokeColor'。但對於svg符號,您可以使用'fillColor'。 –
是啊沒有想到符號,我認爲使用SVG符號是最方便的方式來定義我的標記 – user27