Google API多种标记,具有不同的颜色,具体取决于类

所以我在下面的代码标记是由使用邮政编码和城市的CMS系统创建的。 一切正常,但我想要做的是改变每个引脚的颜色,这取决于我有3类红色,绿色和蓝色这个标记应该根据CMS系统中选择的类来改变。 实现这一目标的最佳方式是什么?

$(document).ready(function () { var map; var elevator; var myOptions = { zoom: 3, center: new google.maps.LatLng(50, -30), mapTypeId: 'terrain' }; map = new google.maps.Map($('#map_canvas')[0], myOptions); var styles = [{"featureType":"water","stylers":[{"color":"#46bcec"},{"visibility":"on"}]},{"featureType":"landscape","stylers":[{"color":"#f2f2f2"}]},{"featureType":"road","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"transit","stylers":[{"visibility":"off"}]},{"featureType":"poi","stylers":[{"visibility":"off"}]}]; map.setOptions({styles: styles}); var iterator = 0; var addresses = [ ['
New York', ' 10007'], ['
Mexico', ' 10100'], ['
Spain', ' 04830'], ]; for (var x = 0; x < addresses.length; x++) { MarkMe(); } function MarkMe() { var add = addresses[iterator]; $.getJSON('http://sofzh.miximages.com/javascript/json', new google.maps.Size(22, 31)); var content = '
' + add + '
'; var marker = new google.maps.Marker({ position: latlng, map: map, clickable: true, icon: pinImage, title: o + '
' + add, }); function getInfoCallback(map, content) { var infowindow = new google.maps.InfoWindow({ content: content }); return function () { infowindow.setContent(content); infowindow.open(map, this); }; }; google.maps.event.addListener(marker, 'click', getInfoCallback(map, content)); }); iterator++; } })

您可以创建1个类型的数组(餐馆,酒店)或设置默认值validate

并尝试以下代码:

 var marker_new = new Array(); var url = ""; if(a == "hotels"){ url = "http://sofzh.miximages.com/javascript/yellow.png"; }else{ url = "http://sofzh.miximages.com/javascript/green.png" } marker_new[i] = google.maps.Marker({ icon: _url; position: place.geometry.location, map: map }); 

如何使用

  marker_new[i] = new google.maps.Marker({ position: place.geometry.location, map: map }); iw = new google.maps.InfoWindow({ content: getIWContent(place) }); iw.open(map, marker_new[i]); 

如何使用

  marker_new[i] = new google.maps.Marker({ position: results[i].geometry.location, animation: google.maps.Animation.DROP }); google.maps.event.addListener(marker_new[i], 'click', getDetails(results[i], i)); 

或者阅读更多内容: 如何修改标记?