hansemannn / titanium-googlemaps

🗺 Use the Google Maps SDK in Titanium
Other
87 stars 26 forks source link

When dragging an annotation, dragend event does not return the new coordinates #61

Closed bitfabrikken closed 7 years ago

bitfabrikken commented 7 years ago

When listening for dragend on a mapView, the parameters supplied for the event does not reflect the new parameters for the dragged annotation.

Quick example:

var win = Ti.UI.createWindow({});
win.open();

var maps = require("ti.googlemaps");
maps.setAPIKey("<YOUR_GOOGLE_MAPS_API_KEY>");

var mapView = maps.createView({
    mapType: maps.MAP_TYPE_TERRAIN,
    indoorEnabled: true,
    indoorPicker: false,
    compassButton: true,
    myLocationButton: true,
    myLocationEnabled: true,
    region: {
        latitude: 37.368122,
        longitude: -121.913653,
        zoom: 0
    }
});
win.add(mapView);

function handleDragEndEvent(e) {
    if (!e.annotation) {
        Ti.API.warn("no annotation in dragend event");
        return;
    }

    //e.annotation.latitude/longitude are still the same here, as they were when annotation was created
    //they should be updated with the coordinates for wherever the annotation was dropped

    Ti.API.warn("annotation dragend, latitude: "+e.annotation.latitude+", longitude: "+e.annotation.longitude);

}
mapView.addEventListener("dragend", handleDragEndEvent);

var annotation = maps.createAnnotation({
    latitude: 37.368122,
    longitude: -121.913653,
    title: "drag me",
    subtitle: "please drag me",
    draggable: true
});

mapView.addAnnotation(annotation);
hansemannn commented 7 years ago

Thanks for all the valuable feedback! 🙂 The error should be fixed in https://github.com/hansemannn/ti.googlemaps/commit/ac1ebb5bb16a7d3b572d8da99c2a12c8d2ef785a, can you try it out?

bitfabrikken commented 7 years ago

NP and thanks for being so fast! It's indeed working.

I made a hunting app recently, which uses ti.map quite a lot. But I am now implementing Google Maps for iOS instead, because Apple Maps doesn't cache maps (for offline use) too well. I will probably find a few more things in the process ;)