[英]Change marker icon with matching id
I'm trying to change the color of an existing pin. 我正在尝试更改现有图钉的颜色。 I have 5 pins with id values running from 1-5.
我有5个ID值从1-5开始的引脚。 can I change the pin if it's say equal to 3. I tried something like the code below but can't quite get what I'm looking for.
如果说等于3,可以更改引脚吗?我尝试了类似下面的代码,但无法完全获得所需的内容。 any help would be great.
任何帮助都会很棒。
if(marker.id == 3){
this.marker.setIcon(myPin2);
}
you can create 1 array of type (restaurants,hotels) or set default value of validate 您可以创建1个类型的数组(餐厅,酒店)或设置validate的默认值
and try this code: 并尝试以下代码:
var marker_new = new Array();
var url = "";
switch (marker.id){
case 1: break;
case 2: break;
case 3:url = "http://exampl.com/yellow.png";
case 4: break;
case 5: break;
}
marker_new[i] = google.maps.Marker({
icon: url;
position: place.geometry.location,
map: map
});
or read more in: How can I modify the markers? 或阅读更多内容: 如何修改标记?
You can try my answer. 你可以试试我的答案。 It accurately worked for me.
它确实为我工作。
if(marker.id == 3){
marker.setIcon(myPin2);
}else{
marker.setIcon(myPin1);
}
If you need to know something else, I am here to help you. 如果您需要了解其他内容,我们会在这里为您提供帮助。 please don't forget to tell me if it worked for you.
请不要忘记告诉我它是否对您有用。 thanks
谢谢
Try this. 尝试这个。
var myPin2 = new google.maps.MarkerImage('imgs/pin2.png');
if(marker.id == 3){
this.marker.setIcon(myPin2);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.