[英]Google Maps Api, Custom marker anchor points
我创建了一个自定义标记用于我的谷歌地图。 图标的锚点应该在左下角。 在我的地图上,锚点似乎位于图标中心的底部边缘。 图标是 32 x 49。我包含的代码放置了我所有的标记。 我已经搜索了几个小时,找不到任何答案。 V3 api 说该属性是锚点。 当我使用该属性时,地图上不会显示任何标记。
var iconImage = "images/Italian Flag Mine New.png";
var map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 12,
center: new google.maps.LatLng(45.067314, 7.697774),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var iconImage = {
url: "images/Italian Flag Mine New.png",
anchorPosition: (0, 49)
};
//var iconImage = {url: "images/Italian Flag Mine New.png",
// anchor : (0,49)};
var marker, i, savedMarker;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][latIndex], locations[i][lngIndex]),
map: map,
animation: google.maps.Animation.DROP,
icon: iconImage
});
}
anchor
属性是标记构造函数的一部分,但您仍然必须根据Google 的文档(在“复杂图标”标题下)创建对象的实例。 试试这个:
var iconImage = {
url: "images/Italian Flag Mine New.png",
anchor: new google.maps.Point(0,49)
};
您还应该考虑指定 size 属性。
您需要指定可点击锚点的坐标,这取决于您将要进行的缩放:
https://developers.google.com/maps/documentation/javascript/markers
// Shapes define the clickable region of the icon.
// The type defines an HTML <area> element 'poly' which
// traces out a polygon as a series of X,Y points. The final
// coordinate closes the poly by connecting to the first
// coordinate.
var shape = {
coord: [9, 0, 6, 1, 4, 2, 2, 4, 0, 8, 0, 12, 1, 14, 2, 16, 5, 19, 7, 23, 8, 26, 9, 30, 9, 34, 11, 34, 11, 15, 49, 16, 49, 30, 12, 26, 13, 24, 14, 21, 16, 18, 18, 16, 20, 12, 20, 8, 18, 4, 16, 2, 15, 1, 13, 0],
type: 'poly'
};
var iconImage= new google.maps.MarkerImage(
// URL
"images/Italian Flag Mine New.png",//желательно название картинки поменять, чтобы было без пробелов
// (width,height)
new google.maps.Size(32, 49),
// The origin point (x,y)
new google.maps.Point(0, 0),
// The anchor point (x,y)
new google.maps.Point(9, 49)
);
marker = new google.maps.Marker({
position : new google.maps.LatLng(locations[i][latIndex], locations[i][lngIndex]),
map : map,
animation: google.maps.Animation.DROP,
icon : iconImage,
shape: shape
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.