2011-11-28 77 views
0

我已经编写了此代码以显示d地图上的多个位置。但是,如果location[i].visit_status为0,我希望标记为红色,如果location[i].visit_status为1(绿色和红色图标在我的机器中),则标记为绿色,因此我编写了此代码,但由于我不知道的原因,它是不工作。任何人都可以帮助我吗?要在地图上显示多个位置的JavaScripts

下面是代码:

var locations=[{"id_retailer":"3","retailer_name":"ret1","retailer_latitude":"3.083826","retailer_longitute":"101.731689","visit_date":"2011-11-11","visit_status":"0"}]; 

var map = new google.maps.Map(document.getElementById('map'), { 

    zoom: 8, 

    center: new google.maps.LatLng(2.67968661580376,102.23876953125), 

    mapTypeId: google.maps.MapTypeId.ROADMAP 

}); 


var infowindow = new google.maps.InfoWindow(); 
var marker, i; 

for (i = 0; i < locations.length; i++) { 

    marker = new google.maps.Marker({ 

    position: new google.maps.LatLng(locations[i].retailer_latitude, locations[i].retailer_longitute), 

    map: map, 
    if(locations[i].visit_status) 
     icon: 'images/1.png'; 
    else 
     icon: 'images/0.png'; 
    title: locations[i].retailer_name 

    }); 

    google.maps.event.addListener(marker, 'click', (function(marker, i) { 

    return function() { 
     infowindow.setContent("Name: "+locations[i].retailer_name); 
     infowindow.open(map, marker); 
    } 

    })(marker, i)); 

} 

window.onunload=GUnload; 
+0

任何机会Rightmove的项目?我有一个谷歌地图的问题,它不会给每个标记正确的标签,它只会给每个标记一样的标签。有时地图很奇怪。 – JackalopeZero

+0

'GUnload'? (在最后一行) - 这是API v2! – TMS

回答

1

更改此语法

map: map, 
    if(locations[i].visit_status) 
     icon: 'images/1.png'; 
    else 
     icon: 'images/0.png'; 

该另一个:

map: map, 
icon: locations[i].visit_status ? 'images/1.png':'images/0.png', 
+0

thanx那么多先生adilson 它的作品很好:) – Alsaket

0

我建议你一样Adilson,而且不要忘了设置图标阴影 - 这是标准图标阴影的示例(如果使用与t形状相同的图标他的标准之一):

icon: locations[i].visit_status ? 'images/1.png' : 'images/0.png', 
shadow: new google.maps.MarkerImage(
    'http://maps.gstatic.com/mapfiles/shadow50.png', 
    null, 
    null, 
    new google.maps.Point(10, 34) 
) 

我想知道一些更好的办法如何指定默认的影子,但I don't know - see this question.

+0

thanx那么多托马斯.. 但我知道为什么我不能看到阴影的图标 – Alsaket

相关问题