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:
Default marker:
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))
});
Custom marker:
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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…