Does Google Maps API V3 support touch event?

后端 未结 2 1981
清歌不尽
清歌不尽 2020-12-11 18:54

We are experiencing an issue related to GoogleMaps. The issue is mainly related to touch screens. We were trying to resolve the issue, but so far no success.

We fou

相关标签:
2条回答
  • 2020-12-11 19:01

    In my experience, the mousedown, mouseup, dragstart, dragend events work fine in place of touchstart, touchmove, touchend.

    google.maps.event.addListener(myMap, "mousedown", function(event){...});
    

    I'm pretty sure that gesture events are not going to be supported, since those are used for pinch-zoom functionality.

    If you need gestures, you'd have to build your own recognizer by tracking mousedown events, storing them in an array, then tracking positions to determine angles, distances etc...

    0 讨论(0)
  • 2020-12-11 19:10

    They aren't currently supported. See here for an interactive map that shows demonstrations of currently available events:

    https://developers.google.com/maps/documentation/javascript/events#EventsOverview

    This page also states that:

    For a complete list of events, consult the Google Maps JavaScript API Reference.

    Touch related events are absent from that page, therefore they aren't supported.

    Commenting on the accepted answer, the events that are supported are not strictly equivalent (a touch is clearly semantically different from a mouse click), and in my experience results can be variable (for example in some cases a touch can result in firing of an onclick event on Google maps, and in some cases it can result in firing of a mouseover event), so some fall-through handling may be required to reliably handle this type of occurence when 'borrowing' these events to detect touch.

    Here's a good article on handling touch with a listener:

    https://www.google.com.au/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwiwm6y38dXXAhWHVbwKHRdUCY4QFggmMAA&url=https%3A%2F%2Fmedium.com%2F%40david.gilbertson%2Fthe-only-way-to-detect-touch-with-javascript-7791a3346685&usg=AOvVaw3pWv0R_AESWKqwF72D0hix

    0 讨论(0)
提交回复
热议问题