[英]Setting custom icon Google Maps
I am trying to use a custom icon and set its size 我正在尝试使用自定义图标并设置其大小
var icon = new google.maps.Icon({
'anchor':null,
'origin':null,
'scaledSize':null,
'size':new google.maps.Size(value.width,value.height),
'url':'../maps/overlay_images/'+value.image
});
Setting the marker on the map, 在地图上设置标记,
var marker = new google.maps.Marker({
position: new google.maps.LatLng(parseFloat(value.latitude), parseFloat(value.longitude)),
map: map,
title: value.name,
icon: icon ,
animation: google.maps.Animation.DROP
});
I get an "Uncaught TypeError: undefined is not a function" error 我得到一个“未捕获的TypeError:undefined不是函数”错误
I could see a Icon object in the maps reference, what am I doing wrong here? 我可以在地图参考中看到一个Icon对象,我在这里做错了什么? https://developers.google.com/maps/documentation/javascript/reference#Icon
https://developers.google.com/maps/documentation/javascript/reference#Icon
google.maps.Icon
is just an object specification, not a class with a constructor. google.maps.Icon
只是一个对象规范,而不是带有构造函数的类。 Your code should look like this: 您的代码应如下所示:
var icon = {
'size':new google.maps.Size(value.width,value.height),
'url':'../maps/overlay_images/'+value.image
};
You can just add a link to the image to display a custom marker icon. 您只需添加图像链接即可显示自定义标记图标。
var marker = new google.maps.Marker({
map: map,
position: position,
icon: "img/marker.png"
});
To edit the size, you can just change the size of the image. 要编辑大小,您只需更改图像的大小即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.