Does Google Maps API V3 support touch event?

2019-01-20 12:39发布

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 found in this article that the Google Maps API V3 does not supports touch event? Is this is true or false?

UPDATE

This issue was handled in the bug

https://issuetracker.google.com/issues/35824421

and was solved in version 3.27 of Google Maps JavaScript API in December 2016.

2条回答
Rolldiameter
2楼-- · 2019-01-20 12:42

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

查看更多
可以哭但决不认输i
3楼-- · 2019-01-20 12:58

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...

查看更多
登录 后发表回答