Google Maps:自定义标记图标-不在矩形中心绘图 [英] Google Maps: Custom Marker Icon - Not plotting at Center of Rectangle
问题描述
尝试绘制边界为lat/lng的矩形区域,并在该区域的中心绘制一个标记,当我使用末端逐渐变细的google maps默认图标时,它会在放大时停留在矩形上/缩小.但是使用自定义图标时,它不会粘贴到矩形区域.请检查小提琴:
Trying to plot a rectangle area with bounds lat/lng, also plotting a marker at the center of the area, when i use the default icon of google maps which is tapering at the end, it sticks to the rectangle on zoom in /zoom out. but when using a custom icon then it does not stick to the rectangle area. please check the fiddles:
默认标记: https://jsfiddle.net/8mQ6G/473/
var myPos = new google.maps.LatLng(47.56715, -122.1556);
var marker = new google.maps.Marker({
position: myPos,
//icon: "https://maps.google.com/mapfiles/kml/shapes/info-i_maps.png",
map: map
});
var rectangle = new google.maps.Rectangle({
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#ffffff',
fillOpacity: 0.35,
map: map,
bounds: new google.maps.LatLngBounds(
new google.maps.LatLng(47.5204, -122.2047),
new google.maps.LatLng(47.6139, -122.1065))
});
自定义标记: https://jsfiddle.net/8mQ6G/472/
var myPos = new google.maps.LatLng(47.56715, -122.1556);
var marker = new google.maps.Marker({
position: myPos,
icon: "https://maps.google.com/mapfiles/kml/shapes/info-i_maps.png",
map: map
});
var rectangle = new google.maps.Rectangle({
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#ffffff',
fillOpacity: 0.35,
map: map,
bounds: new google.maps.LatLngBounds(
new google.maps.LatLng(47.5204, -122.2047),
new google.maps.LatLng(47.6139, -122.1065))
});
使自定义图标在其他位置显示的原因取决于它的左侧还是右侧,因为如果它不像默认图标那样居中,它将始终偏离精确的经度/纬度.请建议是否有解决此问题的方法.
What makes the custom icon plot elsewhere depends on the base of the icon if its to the left or right, since if its not in the center like the default one it will always be away form the exact lat/lng. Please suggest is there any solution to this issue.