简体   繁体   English

地图拖动事件谷歌地图android sdk cordova cordova-plugin-googlemaps

[英]map drag event google maps android sdk cordova cordova-plugin-googlemaps

I am trying to get an event called on map drag or I want to get lat and lon whenever the center of the map change. 我试图在地图拖动时调用一个事件,或者我希望每当地图中心发生变化时都会得到lat和lon。 I am using cordova-plugin-googlemaps which provides native api for google maps. 我正在使用cordova-plugin-googlemaps,它为谷歌地图提供原生api。

map.on(plugin.google.maps.event.CAMERA_CHANGE, function(latLng) {


alert("Map is dragging.\n");});

This does not work. 这不起作用。 Although events like MAP_CLICK does. 虽然像MAP_CLICK这样的事件可以。

See answer below 见下面的答案

var mapdiv = document.getElementById('location-map');
var map = plugin.google.maps.Map.getMap(mapdiv);

var marker = map.addMarker({
    position : {
        lat : latitude,
        lng : longitude,
    },
    animation : plugin.google.maps.Animation.DROP,
    title : 'Lat : ' +latitude+ ', Lng : ' +longitude
});

marker.setDraggable(true);
marker.showInfoWindow();
marker.addEventListener(plugin.google.maps.event.MARKER_DRAG_END, function(point) {
    marker.setTitle('Lat : ' +point.lat+ ', Lng : ' +point.lng);
    marker.showInfoWindow();
});

Find more details at https://github.com/mapsplugin/cordova-plugin-googlemaps 有关详细信息, 访问https://github.com/mapsplugin/cordova-plugin-googlemaps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM