Joh*_*nes 0 javascript label google-maps google-maps-api-3 google-maps-markers
我有一个问题,即使使用JavaScript中的labelColor属性,标签仍将保持黑色,但我想让它变成白色是否有任何方法可以这样做?也许是一种解决方法?
for (i = 0; i < locations.length; i++) {var myLatLng = new google.maps.LatLng(locations[i][1], locations[i][2]);
marker = new google.maps.Marker({
position: myLatLng,
map: map,
label: labels[i],
labelClass: "labels", // the CSS class for the label
labelColor: '#fff',
labelInBackground: false,
icon: locations[i][4]
});
Run Code Online (Sandbox Code Playgroud)
问题是我有自己想要使用的自定义图标,我不想先创建一些SVG.感谢任何可以帮助我的人.
要设置google.maps.Marker的标签属性,您需要使用MarkerLabel对象:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(37.4419, -122.1419),
map: map,
label: {
text: 'A',
color: 'white',
}
});
Run Code Online (Sandbox Code Playgroud)
代码段:
var geocoder;
var map;
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: new google.maps.LatLng(37.4419, -122.1419),
map: map,
label: {
text: 'A',
color: 'white',
}
});
}
google.maps.event.addDomListener(window, "load", initialize);Run Code Online (Sandbox Code Playgroud)
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}Run Code Online (Sandbox Code Playgroud)
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7938 次 |
| 最近记录: |