I am unable to get GPS on iPhones, but works fine on Android (and on simulator). I get a blank error code. I use the sample code in the documentation, and have tried waiting as long as 300 secs.
My code:
function locationHandler( event )
local currentLocation = myMap:getUserLocation()
– table.insert(messages,“requested location”)
if ( currentLocation.errorCode or ( currentLocation.latitude == 0 and currentLocation.longitude == 0 ) ) then
errorText.text = currentLocation.errorMessage
attempts = attempts + 1
if ( attempts > 10 ) then
table.insert(messages,currentLocation.errorMessage)
– native.showAlert( “No GPS Signal”, “Can’t sync with GPS.”, { “OK” } )
else
timer.performWithDelay( 1000, locationHandler )
end
table.insert(messages,"Error getting location: "…errorText.text)
else
table.insert(messages,"Have position: "…currentLocation.longitude)
haveLong = true
latitude = string.format( ‘%0.4f’, currentLocation.latitude)
lat.text = string.format( ‘%0.4f’, currentLocation.latitude)
longitude = string.format( ‘%0.4f’, currentLocation.longitude)
long.text = string.format( ‘%0.4f’, currentLocation.longitude)
end
end
The table.insert is my app message queue. What happens is that every second I get a message "Error getting location: " and the errorText.text is blank (currentLocation.errorMessage is nil).
The map I use is a dummy, I don’t actually need the map, and set it off-screen.
local myMap = native.newMapView( -1, -1, 1, 1 )
When I install the app and start it the first time, the iPhone asks for permission to use GPS. I grant permission.
My build.settings contains:
–
– iOS Section
–
iphone =
{
plist =
{
UIStatusBarHidden = false,
UIPrerenderedIcon = true, – set to false for “shine” overlay
--UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend
NSLocationWhenInUseUsageDescription = “Optimizer needs your location to get your signal.”,
I have verified that the 2 iPhones I have tested have GPS on, and they work fine with an html5 version of the program through Safari.
What am I missing?