'mousemove' only fires once in mobile app

时间:2015-08-07 01:48:36

标签: android cordova google-maps google-maps-api-3 mouseevent

I am creating a phonegap app. In my app I will have a not draggable Google Maps. In the browser, mousemove event fire continuously while I move the mouse around over the map. I expected the same behavior in my mobile phone, but the mousemove only fire once.

This is my main.js file

var app = new function () {
    return {
        initialize: function () {
            var mapCanvas = document.getElementById('map-canvas');
            var mapOptions = {
                center: new google.maps.LatLng(23.5403, -74.5463),
                zoom: 4,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                draggable: false,
            }
            var map = new google.maps.Map(mapCanvas, mapOptions);

            google.maps.event.addDomListener(map, 'mousemove', function (event) {
                console.log('move');
            });

            google.maps.event.addDomListener(map, 'mousedown', function (event) {
                console.log('down', event);
            });
            google.maps.event.addDomListener(map, 'mouseup', function (event) {
                console.log('up', event);
            });
        }
    }
};

google.maps.event.addDomListener(window, 'load', app.initialize);

This is my index.html file

<html>

<head>
    <style>
        #map-canvas {
            width: 100%;
            height: 400px;
            background-color: #CCC;
        }

    </style>
</head>

<body>
    <div id="map-canvas"></div>
    <script src="https://maps.googleapis.com/maps/api/js"></script>
    <script src="lib/jquery-1.8.2.min.js"></script>
    <script src="js/main.js"></script>
</body>
</html>

Could anyone take a look and help my get all the mousemove events? I tried touchmove but I could not make it work with Google Maps.

1 个答案:

答案 0 :(得分:0)

我设法不断添加代码

function move(event) {
    console.log('touchmove', event);
    event.preventDefault();
}

document.getElementById('map-canvas').addEventListener('touchmove', move, false);