I want to get the Icon size of the marker, here the below code, It returning the title and icon name is perfectly returning. But the icon size is not returning, Please help how to get the Icon size from the marker.
var marker = new google.maps.Marker({
position: new google.maps.LatLng(-25.363882,131.044922),
map: map,
title: 'Map',
icon: "travel.png",
size: new google.maps.Size(20, 16)
});
alert("Title"+marker.getTitle());
alert("Icon"+marker.getIcon());
alert("Title"+marker.getIcon().size);
var iconSize = marker.getIcon().size;
var w = iconSize.width;
var h = iconSize.height;
var p1 = projection.fromLatLngToPoint(marker.getPosition());
var p2 = marker.getIcon().anchor;
var sw = new google.maps.Point(p1.x-p2.x-pad,p1.y-p2.y+pad+h);
var ne = new google.maps.Point(p1.x-p2.x+pad+w, p1.y-p2.y-pad);
sw = projection.fromPointToLatLng(sw);
ne = projection.fromPointToLatLng(ne);
iconBounds = new google.maps.LatLngBounds(sw, ne);
Please help!! how to resolve this??
It's because you're not passing an Icon to the marker options, just an URL (which the API supports but then it will only return you a string)
you should create a Icon with the size attribute (else the size property will stay undefined), something like this will work:
var myIcon = { url: "icon.jpg", size: new google.maps.Size(10,10) }; var marker_ new google.maps.Marker({position: Latlng, icon: myIcon});