I’m writing my first location based android app, but got confused about some of the GPS service api. Here are some questions I have:
1) To get my current location, I called requestLocationUpdates() with a listener in the onCreate() method of one activity. But what happens when another activity starts and the current activity goes invisible? Is the GPS location update going to stop? If so, how do I keep it on after the activity is switched?
2) how accurate is the Location.getSpeed()? How is it computed? Can it tell the difference between on bicycle and on foot?
3) not really a question about android. How to calculate the coordinates of a location, say, 100m away from my current location?
4) To stop the GPS, I only need to remove all the listeners that have been registered to locationmanager?
Thanks a lot!
This will not be an exhaustive answer, as I don’t have any experience with Android development, but I just wanted to add my thoughts on your GPS questions:
Question 2:
Normally speed is calculated in the GPS hardware, simply by dividing the change in distance over the change in time.(See comments below) Speed is usually reasonably accurate as long as there is GPS coverage, and you should definitely be able to tell if someone is on foot or on bicycle. You should even be able to tell between normal walking (6 km/h) and slow jogging (12 km/h).Question 3: There is an infinite number of locations at 100m from the current location. Only if you add a bearing, you would be able to derive a destination point. The formula is the following (Source):
You may want to check out the following Stack Overflow post for a JavaScript implementation of the above, which I think should not be difficult to port: