How can I link touch events for a marker on google maps?

google maps api does not support touch events

but now I need to do something on the map and marker, for example, touch the map for a long time, touch the marker, drag the marker.

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

+5
source share
2 answers

I implemented touch events just like shreedhar, but used the "mousedown" event. I found that “click” does not start on mobile devices when using the Google Maps API in a web view (for example, PhoneGap), but the “mousedown" event is triggered by clicking on a mobile device or by clicking on the Internet.

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

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

, infowindow , infowindow "" window.infowindow.

+14

. https://google-developers.appspot.com/maps/documentation/javascript/examples/

Google, - , , -.

gmap : function(lat,lng){
            var stockholm = new google.maps.LatLng(lat, lng);
            var parliament = new google.maps.LatLng(lat, lng);
            var marker;
            var map;
            function initialize() {
                var mapOptions = {
                    zoom: 13,
                    disableDefaultUI: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    center: stockholm
                };
                map = new google.maps.Map(document.getElementById("gmapDiv"),mapOptions);
                marker = new google.maps.Marker({
                    map:map,
                    draggable:true,
                    animation: google.maps.Animation.DROP,
                    position: parliament
                });
               var infowindow = new google.maps.InfoWindow({
                   content: 'content'
               });
                google.maps.event.addListener(marker, 'click', function(){
                  infowindow.open(marker.get('map'), marker);
                  });
            }
            initialize();
        }
+1

All Articles