我想使用Google Maps V3自定义标记标签的颜色,并在文档中搜索我发现有一个名为google.maps.MarkerLabel的类。
在网上搜索我发现了一些使用方法的解释,这是我试图做的事情:
var marker = new google.maps.Marker ({
position: new google.maps.LatLng(data.lat, data.lon),
map: map,
id: data.id,
type: data.type,
type_description: data.type_description,
name: data.name,
via: data.via,
civico: data.civico,
comune: data.comune,
cap: data.cap,
giorno: data.giorno,
orario: data.orario,
description: data.description,
note: data.note,
label: new google.maps.MarkerLabel({
text: data.id,
color: "white"
}),
icon: '<cms:link>../resources/images/' + data.markerIcon + '</cms:link>'
});
该消息告诉我MarkerLabel不是一个costructor。好的,但是我应该把它叫做对象id(当然是一个数字)白色?
谢谢!
答案 0 :(得分:6)
google.maps.MarkerLabel
没有构造函数,它是一个匿名对象。
像这样使用:
var marker = new google.maps.Marker ({
position: map.getCenter(),
map: map,
label: {
text: "A", // data.id,
color: "white"
}
});
代码段
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: map.getCenter(), // new google.maps.LatLng(data.lat, data.lon),
map: map,
label: {
text: "A",
color: "white"
}
});
}
google.maps.event.addDomListener(window, "load", initialize);
&#13;
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
&#13;
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
&#13;