Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i bind touch events for a marker in google maps?

google maps api does not support touch events

but now i need to do some thing on the map and marker, such as long tap the map, tap the marker,drag the marker.

what i wanna do is the same as the google maps client for iOS

like image 579
simon xu Avatar asked Jul 04 '12 02:07

simon xu


People also ask

How do I make a custom marker map?

Create Custom Maps using Google MapsClick on the “Your Places” option in the menu. Click on the “Maps” Tab in the top right. Click on the “CREATE MAP” link at the bottom of the menu. Once you are on the map creation page, click the marker icon to add a marker to the page.

How do I add an event to Google Maps?

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.

How do I put InfoWindow on marker?

Move an info windowAttach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.


1 Answers

I implemented touch events the same way as shreedhar, but using the "mousedown" event. I've found that "click" isn't triggered on mobile devices when using the Google Maps API in a webview (i.e. PhoneGap), but the "mousedown" event is triggered by a tap on mobile or a click on the web.

window.infowindow = new google.maps.InfoWindow({
   content: 'content'
});

google.maps.event.addListener(marker, 'mousedown', function(){
   window.infowindow.open(marker.get('map'), marker);
});

Also, be sure to only define one infowindow variable on your page, and re-use it for all of your markers, hence why I defined infowindow as a "global" variable window.infowindow.

like image 145
Brad Griffith Avatar answered Oct 05 '22 11:10

Brad Griffith