Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

GPS Location on Android

$
0
0

I'm struggling to get any coordinates of my android emulator (API 11, 2.3.3) Titanium 3.1.3.

On iPhone everything works fine. Any idea why this won't work on Android:

var getGeolocation, showGeolocation, win;
 
win = Ti.UI.createWindow({
    title: "Geolocation",
    backgroundColor: "white"
});
 
getGeolocation = function(callback) {
    Ti.Geolocation.distanceFilter = 10;
    Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
    Ti.Geolocation.purpose = "Can I has le geolocation pls";
 
    Titanium.Geolocation.getCurrentPosition(function(e) {
        if (e.error) {
            if (callback) {
                callback(null);
            }
        } else {
            if (callback) {
                callback(e.coords);
            }
        }
    });
};
 
showGeolocation = function(coords) {
    if (coords != null) {
        alert("latitude: " + coords.latitude + "\n longitude: " + coords.longitude);
    } else {
        alert("I don't work on Android :/");
    }
};
 
getGeolocation(showGeolocation);
 
win.open();
I also sent custom coordinates to the emulator via the android device monitor via the provided button.

But always get the error message:

[ERROR][GeolocationModule(  667)] (KrollRuntimeThread) [1751,1751] Unable to get current position, location is null
Thx, Jakob

Viewing all articles
Browse latest Browse all 7655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>