繁体   English   中英

Google Maps API:标记图像定位

[英]Google maps API: Marker image positioning

我已经更改了用于Google地图上marker的图像。 新图像比旧图像宽得多,我注意到标记与latlng对齐,因此标记位于latlng的水平中点。 这不是我想要的,我想让latlng与标记的左侧对齐-我想将marker从默认位置向右偏移80像素。

试试看它的大小。

var markerImage = new google.maps.MarkerImage('/img/icon/here.png',
    new google.maps.Size(80, 80), //size
    new google.maps.Point(0, 0), //origin point
    new google.maps.Point(0, 80)); // offset point
marker[stamp] = new google.maps.Marker({
    position: loc, // loc is a variable with my lngLat object
    title: params.name,
    map: window.gMaps[params.map],
    icon: markerImage
});

您需要MarkerImage的'anchor'属性。 请注意,origin属性在构造函数调用的锚点之前。 如果您不使用精灵,则可以为可选参数发送null。

如果您的标记是80x60,并且您希望锚点位于左侧的中间,请按以下方式创建它:

var markerImage = new google.maps.MarkerImage('customIcon.png', new google.maps.Size(80, 60), null, new google.maps.Point(0, 30));

另请参阅Google的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM