From the few days, I am working with the google map.Google map is a very popular feature on most websites and I want to implement draggable marker feature in Google Map. you can set marker as draggable by setting draggable parameter as true into marker variable.
The following code will allow to provide drag option to google map.
1 2 3 4 5 | var marker = new google.maps.Marker({ draggable: true, }); |
Today I found an issue is when I drag the Marker, the map also starts dragging only for touchscreen devices like mobile.it was working fine with chrome but not in other browsers.
so i got the pretty simple solution for that issue as follows:
1 2 3 4 5 6 7 8 9 | mapObj.setOptions({ draggable: false }); // mapObj is the object of google map }); google.maps.event.addListener(marker, 'dragend', function(){ mapObj.setOptions({ draggable: true }); // mapObj is the object of google map }); |
That’s it.check your map into the touchscreen devices.
Hope this post will helpful for you, waiting for your responses.Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (1)