working on my code to retrieve lat,long by clicking and it works fine. wondering if its possible to combine 'click' and 'dragend' in a single event listener if not. Would appreciate whats a proper alternative.
This is what I've been working on.
google.maps.event.addListener(map,'click', function(event) {
document.getElementById("latbox").value = event.latLng.lat();
document.getElementById("lngbox").value = event.latLng.lng();
addMarker(event.latLng);
});
}
function addMarker(location) {
if (!marker) {
marker = new google.maps.Marker({
position: location,
map: map,
draggable:true,
animation: google.maps.Animation.DROP
});
}
// Otherwise, simply update its location on the map.
else { marker.setPosition(location); }
}
I tried doing this google.maps.event.addListener(map,'click','dragend', function(event)
but to no avail. also if anyone has an idea to modify this marker.setPosition(location);
to have animation: google.maps.Animation.DROP
. . thanks in advance.
To add an event, head to Google Maps on Android, tap on Contribute >Events > Add a public event. You can add an event name, tag the location, and add the time and date of the event as well. There's an option to add an image, write more event details, and add description as well.
getPosition() returns an object, so to specifically get latitude/longitude, you'll have to call lat() and lng() respectively from that.
To ensure that your events appear on Google Maps, enter the address in the “Where” box when you create an event in Google Calendar. As long as you're signed into both Google Calendar and Google Maps, the next time you open Google Maps you'll see your Google Calendar events right there on the map.
As it turns out, the Android Maps Util Library https://github.com/googlemaps/android-maps-utils seems to be the number one choice when clustering markers.
There is no built-in method to apply a listener for multiple events.
When your problem is that you don't want to define the callback-function twice, you may either use a non-anonymous function or define the listener for 1 event and trigger the event when the other event fires:
google.maps.event.addListener( map, 'click',
function(e){ alert('clicked or dragged');} );
google.maps.event.addListener( map, 'dragend', function(){
google.maps.event.trigger(this, 'click');} );
Related to the animation:
Instead of using the marker-methods(setAnimation,setPosition) to set marker-options, you also may use the method setOptions to set multiple options at once:
marker.setOptions({ position : location,
animation : google.maps.Animation.DROP});
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