Google 地图图标放置
Google Map Icon Placement
我正在尝试将我的自定义图标放置在坐标上,如下所示:
[
我知道坐标(在本例中为亚历山大港)经过测试是正确的 here。
我这样调用标记构造函数:
var marker = new google.maps.Marker({
position: {lat: Number(markerData.geodata.lat), lng: Number(markerData.geodata.lng)},
title: '',
icon: {
url: _config.static.marker.default.normal.icon,
size: new google.maps.Size(3, 3, 'rem', 'rem'),
scaledSize: new google.maps.Size(3, 3, 'rem', 'rem'),
anchor: new google.maps.Point(0,0) <-- I think this is where I'm going wrong
},
type: t,
continent: markerData.continent,
country: markerData.country,
id: id,
labelTitle: markerData.name,
label: markerData.name.constructor,
labelClass: 'map-marker-label map-marker-label-village',
zIndex: 1
});
是的,您确实找到了错误的地方,锚点是图像中 lat/lng 坐标所在的点的坐标。
所以如果你想让图钉的底部在lat/lng坐标上,你应该把锚点放在图钉底部像素的图像坐标X/Y上。
在你的情况下它将是:
anchor: new google.maps.Point(27, 54)
因为你想要它在底部的中间
我正在尝试将我的自定义图标放置在坐标上,如下所示:
[
我知道坐标(在本例中为亚历山大港)经过测试是正确的 here。
我这样调用标记构造函数:
var marker = new google.maps.Marker({
position: {lat: Number(markerData.geodata.lat), lng: Number(markerData.geodata.lng)},
title: '',
icon: {
url: _config.static.marker.default.normal.icon,
size: new google.maps.Size(3, 3, 'rem', 'rem'),
scaledSize: new google.maps.Size(3, 3, 'rem', 'rem'),
anchor: new google.maps.Point(0,0) <-- I think this is where I'm going wrong
},
type: t,
continent: markerData.continent,
country: markerData.country,
id: id,
labelTitle: markerData.name,
label: markerData.name.constructor,
labelClass: 'map-marker-label map-marker-label-village',
zIndex: 1
});
是的,您确实找到了错误的地方,锚点是图像中 lat/lng 坐标所在的点的坐标。
所以如果你想让图钉的底部在lat/lng坐标上,你应该把锚点放在图钉底部像素的图像坐标X/Y上。
在你的情况下它将是:
anchor: new google.maps.Point(27, 54)
因为你想要它在底部的中间