Current Device Location

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

How can i get the current location of the device when ever i open the application, i need to get the working code or any link which can guide me to achieve this.

Thanks

2 Answers

I believe this will get your current location. Try putting this in the app.js and alert out the longitude and latitude. It should work.

Titanium.Geolocation.purpose = "";
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 10;
Titanium.Geolocation.getCurrentPosition(function(e)
{
    if (!e.success || e.error)
    {
        alert('error ' + JSON.stringify(e.error));
        return;
    }
    var longitude = e.coords.longitude;
    var latitude = e.coords.latitude;
    var altitude = e.coords.altitude;
    var heading = e.coords.heading;
    var accuracy = e.coords.accuracy;
    var speed = e.coords.speed;
    var timestamp = e.coords.timestamp;
    var altitudeAccuracy = e.coords.altitudeAccuracy;
});

I should point out that the call to getCurrentPosition on Android will return the last known device location which may not be current as it will not turn on any of the location providers to update the location.

Your Answer

Think you can help? Login to answer this question!