gpt4 book ai didi

javascript - TypeError : google. maps.MarkerLabel 不是构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:41:26 25 4
gpt4 key购买 nike

我想使用 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 不是构造函数。好的,但是我应该在哪里调用它来使对象 ID(当然是数字)变成白色?

谢谢!

最佳答案

一个google.maps.MarkerLabel没有构造函数,它是一个匿名对象。

像这样使用它:

var marker = new google.maps.Marker ({
position: map.getCenter(),
map: map,
label: {
text: "A", // data.id,
color: "white"
}
});

proof of concept fiddle

代码片段:

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>

关于javascript - TypeError : google. maps.MarkerLabel 不是构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41268974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com