2014-03-04 169 views
0

如何轻松更改图标的颜色?我只是希望能够使用Google标准标记将其更改为不同的颜色?有没有一种方法可以在var = marker .....中创建标记的地方声明颜色?更改google地图标记颜色

<script type="text/javascript"> 

var map = null; 
function initialize() { 
var myOptions = { 
zoom: 5, 
center: new google.maps.LatLng(54.2361100,-4.5480600), 
mapTypeControl: true, 
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, 
navigationControl: true, 
mapTypeId: google.maps.MapTypeId.ROADMAP 
} 
map = new google.maps.Map(document.getElementById("map_canvas"), 
          myOptions); 

google.maps.event.addListener(map, 'click', function() { 
    infowindow.close(); 
    }); 

var point = new google.maps.LatLng(50.7184100,-3.5339000); 
    var marker = createMarker(point,'<div style="width:200px"><h2>text</h2><\/div>') 


    var point = new google.maps.LatLng(50.9097000,-1.4043500); 
    var marker = createMarker(point,'<div style="width:200px"><h2>text</h2><\/div>') 

} 

var infowindow = new google.maps.InfoWindow(
{ 
size: new google.maps.Size(150,50) 
}); 

function createMarker(latlng, html) { 
var contentString = html; 
var marker = new google.maps.Marker({ 
    position: latlng, 
    map: map, 
    zIndex: Math.round(latlng.lat()*-100000)<<5 
    }); 

google.maps.event.addListener(marker, 'click', function() { 
    infowindow.setContent(contentString); 
    infowindow.open(map,marker); 
    }); 
} 



</script> 
</head> 
<body style="margin:0px; padding:0px;" onload="initialize()"> 
<div id="map_canvas" style="width: 535px; height: 500px"></div> 
+0

http://stackoverflow.com/questions/2472957/how-can-i-change-the-color-of-a-google-maps-marker - 除了这个之外你还需要做什么吗? – Knightsy

+0

是的。我无法得到它的工作。我试过在var marker = createMarker之后放置代码。 ???? – user2208358

回答

1

调整肖恩从这里回答How can I change the color of a Google Maps marker?

试着改变你创建标记功能

function createMarker(latlng, html, iconName) { 
var contentString = html; 
var marker = new google.maps.Marker({ 
    position: latlng, 
    map: map, 
    icon: iconName, 
    zIndex: Math.round(latlng.lat()*-100000)<<5 
}); 

然后用

var marker = createMarker(point,'<div style="width:200px"><h2>text</h2><\/div>', 'brown_markerA.png') 

确保你把所有的图标在同一个地方作为你的地图页面调用它。

然后,您可以调整为不同颜色或字母组成字符串的方式。

+0

试过代码和图标然后消失 – user2208358

+0

我现在没有工作。非常感谢你的帮助。 – user2208358

+0

太棒了,请点击上面的大勾来接受答案。 – Knightsy

相关问题