我认为这起初应该相当容易。但是,如果没有解决方案,我需要花费很多时间在互联网上搜索。
我可以在带有标签的Google地图上添加标记,如下所示:
// Adding a marker to the map
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(22.48, 114.20),
map: map,
title: 'My House',
label: {
text: 'A',
color: '#79E149'
}
});
默认颜色为红色。
我的问题: 如何将标记的红色更改为其他颜色,例如绿色?
我注意到大多数答案建议使用外部图标,例如:
// Adding a marker to the map
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(22.48, 114.20),
map: map,
title: 'My House',
**icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',**
label: {
text: 'A',
color: '#79E149'
}
});
然而: 1.使用此类图标时不会出现标签。
谢谢和最好的问候
亚历
答案 0 :(得分:1)
代码段
var geocoder;
var map;
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(22.48, 114.20),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Adding a marker to the map
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(22.48, 114.20),
map: map,
title: 'My House',
icon: {
url: 'http://maps.google.com/mapfiles/ms/icons/green.png',
labelOrigin: new google.maps.Point(15, 10)
},
label: {
text: 'A',
color: 'black'
}
});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(22.49194, 114.204426),
map: map,
title: 'My Other House',
icon: {
url: 'http://maps.google.com/mapfiles/ms/icons/orange.png',
labelOrigin: new google.maps.Point(15, 10)
},
label: {
text: 'B',
color: 'black'
}
});
}
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>
&#13;
答案 1 :(得分:0)
试试这个
scala> implicit class PimpedInt(x: Int) {
| def +(i: Int, s: String): Int = {
| println(s)
| x + i
| }
| }
defined class PimpedInt
scala> 1 + (1, "hello")
hello
res8: Int = 2