Geolocation Returning Null on iOS Device
I'm trying my app to retrieve the user's current location in my iOS app.
This then passes the longitude and latitude into a web service which retrieves data from my server.
However, on the device it just returns null data meaning it'll bring me back incorrect information.
Can anyone see what I might be doing wrong with the code below?
Hoping it's a easy fix! It's driving me crazy!
Many thanks
Simon
2 Answers
-
Try putting the call to loadgigs() in Titanium.Geolocation.getCurrentPosition(function(e) so that the function doesn't run before you get the coordinates. I don't really see why the data should be returned null from the server
-
just replace your code with the below one and comment the line where you call the loadgigs() method.
Titanium.Geolocation.getCurrentPosition(function(e) { if (!e.success || e.error) { currentLocation.text = 'error: ' + JSON.stringify(e.error); Ti.API.info("Code translation: "+translateErrorCode(e.code)); alert('error ' + JSON.stringify(e.error)); return; } longitude = e.coords.longitude; latitude = e.coords.latitude; altitude = e.coords.altitude; heading = e.coords.heading; accuracy = e.coords.accuracy; speed = e.coords.speed; timestamp = e.coords.timestamp; altitudeAccuracy = e.coords.altitudeAccuracy; loadgigs(); });