0

I'm using Gmaps v3 on a website that performs some functions on the map's click and rightclick events. In the web browser on the computer everything works without problems. Already if I use the browser (whatever it is) from a smartphone these listeners do not work, how can I intercept the click and rightclick events in a browser used in the smartphone?

 map.addListener('rightclick', function(event) {
  var clicked = {lat: event.latLng.lat(), lng: event.latLng.lng()}; 
  infoWindowOptionsMapa.setPosition(clicked);      
  infoWindowOptionsMapa.open(map);
  infoWindows.push(infoWindowOptionsMapa);      
  sessionStorage.removeItem('clicked');
  sessionStorage.setItem('clicked',JSON.stringify(clicked));     
});

google.maps.event.addListener(map,'click',function(e) {
    closeAllInfoWindows();        
    checkClass();  
});

I researched a bit more and tested the code below, but Chrome does not work.

google.maps.event.addListener(map,'mousedown',function(e) {
  var clicked = {lat: e.latLng.lat(), lng: e.latLng.lng()}; 
  alert(clicked);
});
csf
  • 961
  • 3
  • 13
  • 28
  • https://developer.mozilla.org/en-US/docs/Web/API/Touch_events AND http://stackoverflow.com/questions/16168369/does-google-maps-api-v3-support-touch-event Hope this helps – Joonas89 Jan 11 '17 at 13:32

1 Answers1

0

It's not working because on mobile there is no mouse so you can not use click (or rightclick) event.

You should use touch event. It's described well here.

You should use library like jQuery UI Touch Punch, but its meant only for jQuery UI.

You would have to use some workaround to get it to work with Gmaps.

madbarber
  • 123
  • 1
  • 6