Setting mapview.location on android, does not cause the map to recenter on the location.

You must Login before you can answer or comment on any questions.

I have a fairly simple app that displays a map view to a default location. Then I a have an event listener for the geo location. I set the mapview.locatoin to the current location, it displays an icon on the map but does not shift the map to the current location. Anyone have any ideas? Do I need to call some type of repaint?

FYI, this code work fine on iPhone.

Here is my code:

` var isAndroid = false;

if (Titanium.Platform.name == 'android') { isAndroid = true; } var saveLat; var saveLon; var response; var testing = true;

function plotPoints(latitude, longitude){

//var distance = distance(latitude, longitude, saveLat, saveLon, 'M');

if(saveLat != latitude && saveLon != longitude){

    if(testing == true){
        longitude = -87.634887;
        latitude = 41.877654;
    }

    mapview.removeAllAnnotations();
    saveLat = latitude;
    saveLon = longitude;
    var xhr = Ti.Network.createHTTPClient();
    xhr.timeout = 1000000;
    //if(!isNaN(latitude) && !isNaN(longitude)){    
        xhr.open("GET", A WEB ADDRESS);

    //}
    xhr.onload = function()
    {
        try
        {
            response = JSON.parse(this.responseText);


            for(i = 0; i < response.length; i++){

                var rest = Titanium.Map.createAnnotation({
                latitude:response[i].lat,
                longitude:response[i].lon,
                title:response[i].name,
                subtitle:response[i].address + ', '+ response[i].city + ', ' + response[i].zip + ', ' +response[i].phone,
                animate:true,
                myid:i
                });


                if (!isAndroid) {
                    rest.pincolor = Titanium.Map.ANNOTATION_PURPLE;
                    rest.rightButton= Titanium.UI.iPhone.SystemButton.DISCLOSURE;
                } else {
                    rest.pinImage = "/images/map-pin.png";
                }


                mapview.addAnnotation(rest);

            }




        } catch(E){

            //alert(E);
        }
    };

    // Get the data
    xhr.send(); 
}

}

// // create base UI tab and root window // var win1 = Titanium.UI.createWindow({
title:'Tab 1', backgroundColor:'#fff' });

var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, animate:true, region: {latitude:0, longitude:0, latitudeDelta:.035, longitudeDelta:.035}, regionFit:true, userLocation:true }); win1.add(mapview);

// // SHOW CUSTOM ALERT IF DEVICE HAS GEO TURNED OFF //

if (Titanium.Geolocation.locationServicesEnabled==false) { Titanium.UI.createAlertDialog({title:'Member Card Finder', message:'Requires GPS to be turned on.'}).show(); }

Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;

Titanium.Geolocation.distanceFilter = 2;

Titanium.Geolocation.getCurrentPosition(function(e)
{
    if (e.error)
    {
        alert( 'error: ' + JSON.stringify(e.error));
        return;
    }

    if(testing== true){
    longitude = -87.634887;
    latitude = 41.877654;
}
mapview.location = {latitude:latitude, longitude:longitude, latitudeDelta:.035, longitudeDelta:.035};

});

Titanium.Geolocation.addEventListener('location',function(e){

if (e.error)
    {
        alert( 'Application Error Has Occured.');
        return;
    }       

if(testing== true){
    e.coords.longitude = -87.634887;
    e.coords.latitude = 41.877654;
}
mapview.location = {latitude:e.coords.latitude, longitude:e.coords.longitude, latitudeDelta:.035, longitudeDelta:.035};

alert('Changed');
plotPoints(e.coords.latitude, e.coords.longitude);

}); `

Your Answer

Think you can help? Login to answer this question!