I’ve a simple map with an svg file as marker icon. When the map is loaded no problem but, if i try to zoom in or out, the marker changes position (visually) and this is a problem.
The marker must not change position but remain fixed on the reference point.
How can I solve this problem ?
<style type="text/css">
body { font: normal 10pt Helvetica, Arial; }
#map { width: 100%; height: 100%; border: 0px; padding: 0px; }
</style>
<script src="https://maps.google.com/maps/api/js?libraries=geometry&key=AIzaSyBpL5_1SzkA3Q6LATyd19-8g5F_Zq_6w70" type="text/javascript"></script>
<script type="text/javascript">
var icon = {
url: "https://www.aisilbagno.it/wp-content/uploads/2015/04/google-maps-marker-for-residencelamontagne-hi.png", // url
scaledSize: new google.maps.Size(50, 50), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(0, 0), // anchor
};
var icon2 = {
url: "https://cdn-icons-png.flaticon.com/512/1119/1119071.png", // url
scaledSize: new google.maps.Size(50, 50), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(0, 0), // anchor
};
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(icon, lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 350
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(40.8319300, 16.4521000),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: false,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
addMarker(icon, 43.8219355, 16.4221334, '<b>test1</b>');
addMarker(icon, 43.8312300, 16.4121000, '<b>test2</b>');
addMarker(icon2, 43.8319300, 16.4521000, '<b>test3</b>');
}
</script>
<body onLoad="initMap()" style="margin:0px; border:0px; padding:0px;">
<div id="map"></div>
</body>
enter image description here