Problem extenting GPS Sample Program

I’ve tried to modify the GPS sample program so that it reports the GPS position continuously rather that just once, as it does in the sample program. To do this I replaced the following code:

Runtime:addEventListener( “location”, locationHandler )

with this:

function main()
Runtime:addEventListener( “location”, locationHandler )
Runtime:removeEventListener ( “location”, locationHandler );
end
performWithDelayTimer = timer.performWithDelay(10000, main, 0)

Both versions work OK in the simulator. The first version works OK on my Samsung SGH-T769; however, the second version does not work in my Samsung SGH-T769.

Any suggestions would be greatly appreciated.

Thank you.

Ted
[import]uid: 171827 topic_id: 35366 reply_id: 335366[/import]

I’ll ask the folks who know but just speculating…

Are you sitting still while testing this? You shouldn’t have to remove and re-add the listener. The GPS probably only generates events when you move. It would be very draining on the battery to constantly report the location information that hasn’t changed.

As a test you could build for your device, only setting up the listener once and move around, probably more than just around your house too and see if you get other events.

[import]uid: 199310 topic_id: 35366 reply_id: 140577[/import]

I have more information. Apparently hardware like the GPS is quite dependent on the OS and how it’s been implemented. There are other variables like access to the satellites, if location services are using the WiFi etc. I’d still suggest taking your device out into clear air where it can pick up the GPS and see if you get periodic events.

[import]uid: 199310 topic_id: 35366 reply_id: 140579[/import]

Hi Rob,

Thank you.

I can access the GPS OK both indoors and outdoors with the code for the sample program. However, modifying the code as I showed to get continuous readings, I can’t access the GPS anywhere.

By the way, in the code I showed a 10000 ms delay. I’ve tried shorter delays too.

Both versions of my code work in the simulator.

Ted
[import]uid: 171827 topic_id: 35366 reply_id: 140619[/import]

GPS Problem solved!

The following code worked in the GPS sample program:

function main()
timer.performWithDelay(100,Runtime:removeEventListener ( “location”, locationHandler ));
Runtime:addEventListener( “location”, locationHandler )
end
Runtime:addEventListener( “location”, locationHandler )
performWithDelayTimer = timer.performWithDelay(500, main, 0)

This code replaces the following in that program:

Runtime:addEventListener( “location”, locationHandler )

I don’t know what is under the hood in the Simulator and in my mobile phone, so I don’t know why it worked. [import]uid: 171827 topic_id: 35366 reply_id: 140665[/import]

I’ll ask the folks who know but just speculating…

Are you sitting still while testing this? You shouldn’t have to remove and re-add the listener. The GPS probably only generates events when you move. It would be very draining on the battery to constantly report the location information that hasn’t changed.

As a test you could build for your device, only setting up the listener once and move around, probably more than just around your house too and see if you get other events.

[import]uid: 199310 topic_id: 35366 reply_id: 140577[/import]

I have more information. Apparently hardware like the GPS is quite dependent on the OS and how it’s been implemented. There are other variables like access to the satellites, if location services are using the WiFi etc. I’d still suggest taking your device out into clear air where it can pick up the GPS and see if you get periodic events.

[import]uid: 199310 topic_id: 35366 reply_id: 140579[/import]

Hi Rob,

Thank you.

I can access the GPS OK both indoors and outdoors with the code for the sample program. However, modifying the code as I showed to get continuous readings, I can’t access the GPS anywhere.

By the way, in the code I showed a 10000 ms delay. I’ve tried shorter delays too.

Both versions of my code work in the simulator.

Ted
[import]uid: 171827 topic_id: 35366 reply_id: 140619[/import]

GPS Problem solved!

The following code worked in the GPS sample program:

function main()
timer.performWithDelay(100,Runtime:removeEventListener ( “location”, locationHandler ));
Runtime:addEventListener( “location”, locationHandler )
end
Runtime:addEventListener( “location”, locationHandler )
performWithDelayTimer = timer.performWithDelay(500, main, 0)

This code replaces the following in that program:

Runtime:addEventListener( “location”, locationHandler )

I don’t know what is under the hood in the Simulator and in my mobile phone, so I don’t know why it worked. [import]uid: 171827 topic_id: 35366 reply_id: 140665[/import]