Can't get location events on android devices

Hie

I’m trying to create an app that uses GPS (location) on android and iphone.
While on the iphone I’m getting all the data, on the android devices I don’t get that event at all.

Even when I try to run the sample code (GPS), I don’t get any data at all but I do get the compass app working (heading data).

I’ve tried running on Samsung Galaxy SII 4.0 and on Nexus 1 (the old one) running 2.3.3 and on both the app runs but no event is fired or data is received.

Any ideas? [import]uid: 13553 topic_id: 31410 reply_id: 331410[/import]

In the device settings, try turning on the GPS… (location and privacy settings on my android version)…

Also, there’s settings in there for “Use other sources” for determining location (wifi, cell network)… Turn them all on to get the fastest GPS response…

If you only have the GPS on, and not the others, you might not receive a GPS signal inside a building (satellites blocked), so turning on the other methods helps indoors… [import]uid: 79933 topic_id: 31410 reply_id: 125596[/import]

Hey Mpappas

Thanks for the help but I tried all of this.
I get heading so the GPS is on and I also double checked that it’s all on (wifi and cell towers).
I can use the maps and navigation apps other than this but not using corona.

Any other options? [import]uid: 13553 topic_id: 31410 reply_id: 125597[/import]

So you have something like this in your code, and it’s not generating events on android?

Runtime:addEventListener( “location”, locationHandler )

[import]uid: 79933 topic_id: 31410 reply_id: 125599[/import]

Of course…
I’m using the GPS sample code. it works fine on iPhone but no response on android.

Whats really weird is that I can run the Compass demo without any issues (heading only) but I can’t seem to get location data what so ever.

Shahar [import]uid: 13553 topic_id: 31410 reply_id: 125601[/import]

Well, I’m using the same locanHandler event, and I am getting updates… I’m using the latest daily build, but it worked with builds even before android maps! (my map code was commented out for droid until then, but my locanHandler wasn’t, and droid was getting the events for location even back then).

Maybe there’s something about the build you are using, or the particular version of android the devices are running, or the devices themselves…

There’s nothing obvious from your description… Maybe Joshua could help if you posted your location code, and information about your build and device OS versions? [import]uid: 79933 topic_id: 31410 reply_id: 125607[/import]

I’ve been using this code successfully on iOS 5.1.1 iPhone 4 device.
I’ve been trying to run this on Nexus1 2.3.3 and Samsung Galaxy SII 4.0.3 running a mobile provider official rom (not rooted or anything).

This is the code I’ve been using -

[code]
local widget = require( “widget” )

local currentLatitude = 0
local currentLongitude = 0

display.setStatusBar( display.HiddenStatusBar )

local background = display.newImage(“gps_background.png”)

local latitude = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
latitude:setReferencePoint( display.CenterLeftReferencePoint )
latitude.x, latitude.y = 125 + latitude.contentWidth * 0.5, 64
latitude:setTextColor( 255, 85, 85 )
local longitude = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
longitude:setReferencePoint( display.CenterLeftReferencePoint )
longitude.x, longitude.y = 125 + longitude.contentWidth * 0.5, latitude.y + 50
longitude:setTextColor( 255, 85, 85 )
local altitude = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
altitude:setReferencePoint( display.CenterLeftReferencePoint )
altitude.x, altitude.y = 125 + altitude.contentWidth * 0.5, longitude.y + 50
altitude:setTextColor( 255, 85, 85 )
local accuracy = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
accuracy:setReferencePoint( display.CenterLeftReferencePoint )
accuracy.x, accuracy.y = 125 + altitude.contentWidth * 0.5, altitude.y + 50
accuracy:setTextColor( 255, 85, 85 )
local speed = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
speed:setReferencePoint( display.CenterLeftReferencePoint )
speed.x, speed.y = 125 + speed.contentWidth * 0.5, accuracy.y + 50
speed:setTextColor( 255, 85, 85 )
local direction = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
direction:setReferencePoint( display.CenterLeftReferencePoint )
direction.x, direction.y = 125 + direction.contentWidth * 0.5, speed.y + 50
direction:setTextColor( 255, 85, 85 )
local time = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
time:setReferencePoint( display.CenterLeftReferencePoint )
time.x, time.y = 125 + time.contentWidth * 0.5, direction.y + 50
time:setTextColor( 255, 85, 85 )

local buttonPress = function( event )
– Show location on map
mapURL = “http://maps.google.com/maps?q=Hello,+Corona!@” … currentLatitude … “,” … currentLongitude
system.openURL( mapURL )
end
local button1 = widget.newButton{
default = “buttonRust.png”,
over = “buttonRustOver.png”,
onPress = buttonPress,
label = “Show on Map”,
font = “TrebuchetMS-Bold”,
fontSize = 22,
labelColor = { default = { 200, 200, 200, 255}, over = { 200, 200, 200, 128 } },
emboss = true,
}
button1.x, button1.y = 160, 422

local locationHandler = function( event )

– Check for error (user may have turned off Location Services)
if event.errorCode then
native.showAlert( “GPS Location Error”, event.errorMessage, {“OK”} )
print( "Location error: " … tostring( event.errorMessage ) )
else

local latitudeText = string.format( ‘%.4f’, event.latitude )
currentLatitude = latitudeText
latitude.text = latitudeText
latitude.x, latitude.y = 125 + latitude.contentWidth * 0.5, 64

local longitudeText = string.format( ‘%.4f’, event.longitude )
currentLongitude = longitudeText
longitude.text = longitudeText
longitude.x, longitude.y = 125 + longitude.contentWidth * 0.5, latitude.y + 50

local altitudeText = string.format( ‘%.3f’, event.altitude )
altitude.text = altitudeText
altitude.x, altitude.y = 125 + altitude.contentWidth * 0.5, longitude.y + 50

local accuracyText = string.format( ‘%.3f’, event.accuracy )
accuracy.text = accuracyText
accuracy.x, accuracy.y = 125 + accuracy.contentWidth * 0.5, altitude.y + 50

local speedText = string.format( ‘%.3f’, event.speed )
speed.text = speedText
speed.x, speed.y = 125 + speed.contentWidth * 0.5, accuracy.y + 50

local directionText = string.format( ‘%.3f’, event.direction )
direction.text = directionText
direction.x, direction.y = 125 + direction.contentWidth * 0.5, speed.y + 50

– Note: event.time is a Unix-style timestamp, expressed in seconds since Jan. 1, 1970
local timeText = string.format( ‘%.0f’, event.time )
time.text = timeText
time.x, time.y = 125 + time.contentWidth * 0.5, direction.y + 50
end
end

– Determine if running on Corona Simulator

local isSimulator = “simulator” == system.getInfo(“environment”)

– Location Events is not supported on Simulator

if isSimulator then
msg = display.newText( “Location events not supported on Simulator!”, 0, 230, “Verdana-Bold”, 13 )
msg.x = display.contentWidth/2 – center title
msg:setTextColor( 255,255,255 )
end

– Activate location listener
Runtime:addEventListener( “location”, locationHandler )

[/code] [import]uid: 13553 topic_id: 31410 reply_id: 125612[/import]

I’ve had success with gps on android as well.

For me the key was waiting long enough for the gps lock (some android gps systems take a LONG time to get a lock), and permissions.

See this thread:

https://developer.coronalabs.com/forum/2012/02/28/gps-android [import]uid: 9070 topic_id: 31410 reply_id: 125614[/import]

Wow - I’m stumped.

That looks like (well organized) plain vanilla code for getting the location. Doesn’t look like anything is wrong with it AT ALL. Same type of code works mint on my motorola atrix, and a couple other droids I’ve tested on…

Hopefully Jason Quick or someone has an idea. [import]uid: 79933 topic_id: 31410 reply_id: 125615[/import]

I’m using the corona GPS example and I’m stomped as well since I know I’ve used this before.
I’m using this now with the latest daily builds and a couple back and nothing works.

Thanks for all the help - I will go over all the threads and give it a go with the latest public build and will report back.

It’s fun to find weird bugs but not this time :-/

BR,
Shahar [import]uid: 13553 topic_id: 31410 reply_id: 125619[/import]

You know, on another thread regarding a problem with android maps… Jason gave an answer that implied the GPS was tied with MapViews on android (not the locationHandler)… And I couldn’t avoid taking a hit for the GPS power, while a map was still instantiated…

http://developer.coronalabs.com/forum/2012/09/08/android-battery-issue-gps

Do you have a map onscreen / created? If not, I wonder if you created a mapView, if the GPS would kick on (like, jason might have been playing with how GPS is activated on android when he did the new android mapViews, and messed something up)… [import]uid: 79933 topic_id: 31410 reply_id: 125633[/import]

In the device settings, try turning on the GPS… (location and privacy settings on my android version)…

Also, there’s settings in there for “Use other sources” for determining location (wifi, cell network)… Turn them all on to get the fastest GPS response…

If you only have the GPS on, and not the others, you might not receive a GPS signal inside a building (satellites blocked), so turning on the other methods helps indoors… [import]uid: 79933 topic_id: 31410 reply_id: 125596[/import]

Hey Mpappas

Thanks for the help but I tried all of this.
I get heading so the GPS is on and I also double checked that it’s all on (wifi and cell towers).
I can use the maps and navigation apps other than this but not using corona.

Any other options? [import]uid: 13553 topic_id: 31410 reply_id: 125597[/import]

So you have something like this in your code, and it’s not generating events on android?

Runtime:addEventListener( “location”, locationHandler )

[import]uid: 79933 topic_id: 31410 reply_id: 125599[/import]

Of course…
I’m using the GPS sample code. it works fine on iPhone but no response on android.

Whats really weird is that I can run the Compass demo without any issues (heading only) but I can’t seem to get location data what so ever.

Shahar [import]uid: 13553 topic_id: 31410 reply_id: 125601[/import]

Well, I’m using the same locanHandler event, and I am getting updates… I’m using the latest daily build, but it worked with builds even before android maps! (my map code was commented out for droid until then, but my locanHandler wasn’t, and droid was getting the events for location even back then).

Maybe there’s something about the build you are using, or the particular version of android the devices are running, or the devices themselves…

There’s nothing obvious from your description… Maybe Joshua could help if you posted your location code, and information about your build and device OS versions? [import]uid: 79933 topic_id: 31410 reply_id: 125607[/import]

I’ve been using this code successfully on iOS 5.1.1 iPhone 4 device.
I’ve been trying to run this on Nexus1 2.3.3 and Samsung Galaxy SII 4.0.3 running a mobile provider official rom (not rooted or anything).

This is the code I’ve been using -

[code]
local widget = require( “widget” )

local currentLatitude = 0
local currentLongitude = 0

display.setStatusBar( display.HiddenStatusBar )

local background = display.newImage(“gps_background.png”)

local latitude = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
latitude:setReferencePoint( display.CenterLeftReferencePoint )
latitude.x, latitude.y = 125 + latitude.contentWidth * 0.5, 64
latitude:setTextColor( 255, 85, 85 )
local longitude = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
longitude:setReferencePoint( display.CenterLeftReferencePoint )
longitude.x, longitude.y = 125 + longitude.contentWidth * 0.5, latitude.y + 50
longitude:setTextColor( 255, 85, 85 )
local altitude = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
altitude:setReferencePoint( display.CenterLeftReferencePoint )
altitude.x, altitude.y = 125 + altitude.contentWidth * 0.5, longitude.y + 50
altitude:setTextColor( 255, 85, 85 )
local accuracy = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
accuracy:setReferencePoint( display.CenterLeftReferencePoint )
accuracy.x, accuracy.y = 125 + altitude.contentWidth * 0.5, altitude.y + 50
accuracy:setTextColor( 255, 85, 85 )
local speed = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
speed:setReferencePoint( display.CenterLeftReferencePoint )
speed.x, speed.y = 125 + speed.contentWidth * 0.5, accuracy.y + 50
speed:setTextColor( 255, 85, 85 )
local direction = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
direction:setReferencePoint( display.CenterLeftReferencePoint )
direction.x, direction.y = 125 + direction.contentWidth * 0.5, speed.y + 50
direction:setTextColor( 255, 85, 85 )
local time = display.newText( “–”, 0, 0, “DBLCDTempBlack”, 26 )
time:setReferencePoint( display.CenterLeftReferencePoint )
time.x, time.y = 125 + time.contentWidth * 0.5, direction.y + 50
time:setTextColor( 255, 85, 85 )

local buttonPress = function( event )
– Show location on map
mapURL = “http://maps.google.com/maps?q=Hello,+Corona!@” … currentLatitude … “,” … currentLongitude
system.openURL( mapURL )
end
local button1 = widget.newButton{
default = “buttonRust.png”,
over = “buttonRustOver.png”,
onPress = buttonPress,
label = “Show on Map”,
font = “TrebuchetMS-Bold”,
fontSize = 22,
labelColor = { default = { 200, 200, 200, 255}, over = { 200, 200, 200, 128 } },
emboss = true,
}
button1.x, button1.y = 160, 422

local locationHandler = function( event )

– Check for error (user may have turned off Location Services)
if event.errorCode then
native.showAlert( “GPS Location Error”, event.errorMessage, {“OK”} )
print( "Location error: " … tostring( event.errorMessage ) )
else

local latitudeText = string.format( ‘%.4f’, event.latitude )
currentLatitude = latitudeText
latitude.text = latitudeText
latitude.x, latitude.y = 125 + latitude.contentWidth * 0.5, 64

local longitudeText = string.format( ‘%.4f’, event.longitude )
currentLongitude = longitudeText
longitude.text = longitudeText
longitude.x, longitude.y = 125 + longitude.contentWidth * 0.5, latitude.y + 50

local altitudeText = string.format( ‘%.3f’, event.altitude )
altitude.text = altitudeText
altitude.x, altitude.y = 125 + altitude.contentWidth * 0.5, longitude.y + 50

local accuracyText = string.format( ‘%.3f’, event.accuracy )
accuracy.text = accuracyText
accuracy.x, accuracy.y = 125 + accuracy.contentWidth * 0.5, altitude.y + 50

local speedText = string.format( ‘%.3f’, event.speed )
speed.text = speedText
speed.x, speed.y = 125 + speed.contentWidth * 0.5, accuracy.y + 50

local directionText = string.format( ‘%.3f’, event.direction )
direction.text = directionText
direction.x, direction.y = 125 + direction.contentWidth * 0.5, speed.y + 50

– Note: event.time is a Unix-style timestamp, expressed in seconds since Jan. 1, 1970
local timeText = string.format( ‘%.0f’, event.time )
time.text = timeText
time.x, time.y = 125 + time.contentWidth * 0.5, direction.y + 50
end
end

– Determine if running on Corona Simulator

local isSimulator = “simulator” == system.getInfo(“environment”)

– Location Events is not supported on Simulator

if isSimulator then
msg = display.newText( “Location events not supported on Simulator!”, 0, 230, “Verdana-Bold”, 13 )
msg.x = display.contentWidth/2 – center title
msg:setTextColor( 255,255,255 )
end

– Activate location listener
Runtime:addEventListener( “location”, locationHandler )

[/code] [import]uid: 13553 topic_id: 31410 reply_id: 125612[/import]

I’ve had success with gps on android as well.

For me the key was waiting long enough for the gps lock (some android gps systems take a LONG time to get a lock), and permissions.

See this thread:

https://developer.coronalabs.com/forum/2012/02/28/gps-android [import]uid: 9070 topic_id: 31410 reply_id: 125614[/import]

Wow - I’m stumped.

That looks like (well organized) plain vanilla code for getting the location. Doesn’t look like anything is wrong with it AT ALL. Same type of code works mint on my motorola atrix, and a couple other droids I’ve tested on…

Hopefully Jason Quick or someone has an idea. [import]uid: 79933 topic_id: 31410 reply_id: 125615[/import]

I’m using the corona GPS example and I’m stomped as well since I know I’ve used this before.
I’m using this now with the latest daily builds and a couple back and nothing works.

Thanks for all the help - I will go over all the threads and give it a go with the latest public build and will report back.

It’s fun to find weird bugs but not this time :-/

BR,
Shahar [import]uid: 13553 topic_id: 31410 reply_id: 125619[/import]