Reputation: 474
I have google map with search box , i want to access marker position with (lat , lng ) when i search specific place , i can access location exactly when i drag & drop marker by event.addListener
var marker = new google.maps.Marker({
position: place.geometry.location,
map: map,
draggable:true,
title:"Drag me!",
});
google.maps.event.addListener(marker, 'dragend', function(position:any){
This.centerLat = position.latLng.lat().toFixed(3)
This.centerLng = position.latLng.lng().toFixed(3)
});
but i want to get marker location when search is done without drag
& drop
Upvotes: 0
Views: 436
Reputation: 474
I found this answer too , and it work with me correctly :
var marker = new google.maps.Marker({
position: place.geometry.location,
map: map,
draggable:true,
title:"Drag me!",
});
google.maps.event.addListener(marker, "map_changed", function() {
this.centerLat = place.geometry.location.lat().toFixed(3)
this.centerLng = place.geometry.location.lng().toFixed(3)
});
Upvotes: 0
Reputation: 133400
You can obtain the coords of a marker using
pos = yourMarker.getPosition();
the result is an object with lat and lng
lat = pos.lat;
lng = pos.lng;
https://developers.google.com/maps/documentation/javascript/reference/marker?hl=en#Marker
Upvotes: 1