Ammar
Ammar

Reputation: 1821

Titanium mapview not working well

I'm using Geocoder to to translate the address, given through a text field, in terms of latitude and longitude and then set the map region to that location as follows.

var location = Titanium.UI.createTextField({...});
var btnSearch = Titanium.UI.createButton({...});
var mapview = Titanium.Map.createView({
    top: 75,    height: 350,
    mapType: Titanium.Map.SATELLITE_TYPE,
    animate: true,  regionFit: true,    userLocation: true
});
btnSearch.addEventListener('click',function(e){
    if(location.value != '') {
        Ti.Geolocation.forwardGeocoder(location.value, function(e){
            Ti.API.info(location.value + '\'s co-ordinates are: ' + e.latitude + ' lat, ' + e.longitude + ' lon');
            mapview.region = {latitude: e.latitude, longitude: e.longitude, latitudeDelta:0.1, longitudeDelta:0.1};
        });
    } 
    else {
        alert('You must provide a start address!');
    }
});

The translation process works fine but the map region is not set to new coordinates in mapview. If anybody knows the cause of this problem, please help me.

Thanks.

Upvotes: 1

Views: 560

Answers (1)

Joonas
Joonas

Reputation: 2182

Try this
mapview.setLocation({latitude: e.latitude, longitude: e.longitude, latitudeDelta:0.1, longitudeDelta:0.1});

Upvotes: 2

Related Questions