hansemannn / titanium-googlemaps

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

Crashes when using cameraUpdate methods #69

Closed bitfabrikken closed 7 years ago

bitfabrikken commented 7 years ago

No matter which method I use on cameraUpdate, the app crashes. I think there might be a generel bug here causing it, or maybe I'm using it incorrectly?

Errors

Jan 25 09:08:20 Dans-Mac-mini SpringBoard[67831]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Jan 25 09:08:20 Dans-Mac-mini com.apple.CoreSimulator.SimDevice.78A29E35-2726-46BF-8A9B-12A768CB0AF5.launchd_sim[67814] (UIKitApplication:dk.bitfabrikken.test[0x22e7][49115]): Service exited due to Segmentation fault: 11

Example

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

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

var mapView = maps.createView({
    mapType: maps.MAP_TYPE_TERRAIN,
    indoorEnabled: false,
    indoorPicker: false,
    compassButton: false,
    myLocationButton: false,
    myLocationEnabled: false,
    region: {
        latitude: 10.00,
        longitude: 10.000,
        zoom: 3
    }
});
win.add(mapView);

var button = Ti.UI.createButton({
    backgroundColor: "white", color: "black",
    title: "click me",
});
button.addEventListener('click',function(e){
    test();
});
mapView.add(button);

//this crashes the map

function test(){

    var cameraUpdate = maps.createCameraUpdate();
    cameraUpdate.setTarget({latitude: 11.000, longitude: 11.000, zoom: 7}); //this causes the crash

    //this, I think, is the proper parameters for fitBounds, the README is incorrect for this
    /*
    cameraUpdate.fitBounds({
        padding: 0, 
        insets: 0, 
        bounds: { 
            coordinate1: {latitude: 0, longitude: 1},
            coordinate2: { latitude: 100, longitude: 100}
        }
    });
    */

    mapView.moveCamera(cameraUpdate);

} 
hansemannn commented 7 years ago

Good catch! Fixed the general crash in https://github.com/hansemannn/ti.googlemaps/commit/5724119e1008c80bd695075715f3902446df096e. For the fitBounds method, I need to validate it before pushing the new 2.7.2 version. It's already bumped, so please try it out.

hansemannn commented 7 years ago

Ok, so here is the deal for fitBounds:

It looks correct from the implementation-side, so I'll check and update the docs.

hansemannn commented 7 years ago

Updated the readme with examples for all methods.

bitfabrikken commented 7 years ago

Works now :) Could you possible make it so you can see latitude, longitude and zoom on the cameraUpdate object?

hansemannn commented 7 years ago

Possible yes, but I won't do it, because not all methods use a latitude / longitude to specify a location, so it would rather irritate than help.

bitfabrikken commented 7 years ago

@hansemannn ok, perhaps you have an idea to achieve this then?

Create and show a map with annotations and immediately show it centered and bounded to those annotations.

Best I can come up with now is to first show the map, then use the cameraUpdate.fitBounds - but that causes the map to be shown first and then "snap" into place

hansemannn commented 7 years ago

@bitfabrikken Listen to the render-events (either regionchanged or complete of the map and call the method inside there. Add the event listeners to those on-open and remove them on-focus, so the states are clean.

bitfabrikken commented 7 years ago

@hansemannn thanks :)