问题描述
我想使用Google Maps V3自定义标记的标签颜色,然后在文档中搜索我发现有一个名为google.maps.MarkerLabel的类.
I want to customize the color of the label of my marker with Google Maps V3, and searching on the documentation I've found that there's a class named google.maps.MarkerLabel.
在网络上搜索后,我发现了一些用法说明,这是我尝试做的事情:
Searching on the web I've found some explaes of usage and here's what I've tried to do:
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不是构造函数.好的,但是我应该在哪里通过白色的对象ID(当然是数字)来调用它呢?
The message tells me MarkerLabel is not a costructor. Ok, but where should I call it to make by object id (which is of course a number) coloured white?
谢谢!
推荐答案
a google.maps.MarkerLabel
没有构造函数,它是一个匿名对象.
a google.maps.MarkerLabel
doesn't have a constructor, it is an anonymous object.
像这样使用它:
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);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas"></div>
这篇关于TypeError:google.maps.MarkerLabel不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!