开发者

Longpress event on Google Maps API?

I'm creating a web app for mob开发者_高级运维ile phones where if they longpress a certain part of the map, something happens. Unfortunately I can't use a window.setTimeout(..) with a mousedown/mouseup combination because the Maps API doesn't contain those events as it would disrupt the drag events. Is there another way to do this? There has to be a way because the Maps webapp on mobile pops up the same menu when you longpress as right-click on Google maps for computers - just don't know how! Please let me know!!

Thanks in advance!


I don't see any reason you can't use the DOM mousedown/mouseup events rather the the Maps API events to detect a long press. You can even use the Maps API to attach the listeners, for example (assuming you have as the element containing the map):

 google.maps.event.addDomListener(document.getElementById('map_canvas'), 'mousedown', function () { console.log("Test") });


Excellent question. After much digging, I found the following page on touch and gesture events for Android and iPhone. Hopefully this list will be of some use to you:

http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events.html

To elaborate, you're probably going to want to handle the touchstart and touchend events, perhaps keeping track of the position of the "cursor" at each to determine if it was a drag or simply a press. Good luck, and I don't blame you if you don't consider this a definitive answer. :P

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜