In google map usually the center bottom of the image of the marker is the lat lng of a point that it has to mark.
Imagine my marker icon is a circle, I would like the center of it to be at the lat-lng of the given point...
Code:
var image_hotspot = 'img/icons/bank_euro.png'; var marker = new google.maps.Marker({ map: map, position: placeLoc, icon: image_hotspot });
You can add a simple marker to the map at a desired location by instantiating the marker class and specifying the position to be marked using latlng, as shown below.
The transition() and moveMarker() are used to move marker smoothly on click on the Google map.
Call the changeMarkerPosition() function and pass the marker object in it. The setPosition() will change the marker position on google map based on the specified latitude and longitude.
For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.
What You need is to create a MarkerImage
object, for example:
var markerImage = new google.maps.MarkerImage('img/icons/bank_euro.png', new google.maps.Size(30, 30), new google.maps.Point(0, 0), new google.maps.Point(15, 15));
Where first parameter is an image url, second is image size, third is origin point of image, and fourth is position on the image where marker should point. If your marker is a circle then set fourth parameter to center of the image. And create your marker passing markerImage
to icon property:
var marker = new google.maps.Marker({ map: map, position: placeLoc, icon: markerImage });
From the docs:
Converting MarkerImage objects to type Icon
var image = new google.maps.MarkerImage( place.icon, new google.maps.Size(71, 71), new google.maps.Point(0, 0), new google.maps.Point(17, 34), new google.maps.Size(25, 25));
becomes
var image = { url: place.icon, size: new google.maps.Size(71, 71), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(17, 34), scaledSize: new google.maps.Size(25, 25) };
https://developers.google.com/maps/documentation/javascript/markers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With