Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Adding annotation to mapview makes the application crash

I'm currently working on an application where we need to show a location using Google maps.
We have an if statement that does a Geocoder lookup if we don't have latitude and longitude and if we do have the latitude and longitude it just adds the annotation to the map.
The problem is that when we already have the latitude/longitude and we try to add the annotation without any lookups the application crashes with a "Wrapped java.lang.NullPointerException" error - But if we do a lookup first then it works fine.
If we do a lookup even if we have the coordinates and just don't use the lookup for anything then it also works - It seems like the lookup delays the function for just a fraction of a second which is enough for it to work.

Trying to use the "complete" event doesn't trigger on Android.

Anybody have an idea for a solution?

To Appcelerator: Could you please work on actually supporting a lot of the events on Android as well - This is the 15th time in the last two days that i need to use an event that doesn't fire on Android. Very very frustrating!

var mapView = Titanium.Map.createView({
        mapType: Titanium.Map.STANDARD_TYPE,
        userLocation:false,
        top:130,
        bottom:0,
        visible:false
    });

    var createAnnotation = function(params) {
        params.title = params.title ? params.title : data.headline;

        var annotation = Titanium.Map.createAnnotation({
            latitude:params.latitude,
            longitude:params.longitude,
            title:params.title,
            pinImage:"../images/map-pin.png",
            animate:true
        });

        mapView.addAnnotation(annotation);
        mapView.region={
                latitude: params.latitude,
                longitude: params.longitude,
                latitudeDelta:0.05,
                longitudeDelta:0.05
        };
    };


    if(!data.longitude || !data.latitude) {
        Titanium.Geolocation.forwardGeocoder(data.address+' '+data.zipcode+', '+data.city,function(response){
            createAnnotation({
                longitude:response.longitude,
                latitude:response.latitude
            });
        });
    } else {
            createAnnotation({
                longitude:data.longitude,
                latitude:data.latitude
            });    
    }

    win.add(mapView);
— asked December 7th 2010 by Michael Lykke
  • android
  • complete
  • crash
  • event
  • mapview
2 Comments
  • you code is missing some information that would allow someone to help you.

    the createAnnotation function references params.title, data.headline

    — commented December 7th 2010 by Aaron Saunders
  • Michael,

    Maybe i am totaly off here, but have you checked if your ' java.lang.NullPointerException' arent related to the variables you are passing? Like: 'params.title' or 'data.headline' or the 'data' in general?

    Adding stuff to annotations was giving me hell.. Since i started checking if there was some nulls from the database the problems disapeared.

    cheers

    — commented December 22nd 2010 by Daniel Ander

0 Answers

The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.