tags:

views:

257

answers:

2

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!

+1  A: 

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):

lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))
lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))

d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius

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:

Daniel Vassallo
Actually, GPS receivers measure speed directly rather than distance over time, and so the speed is significantly more accurate than you'd expect from the position accuracy.
Andrew McGregor
@Andrew: But it still has to be distance over time internally, at least for consumer GPS receivers without accelerometers or other technology.
Daniel Vassallo
No, it's not, that's what I'm saying: the receiver can get speed from the phase variation in the radio signal directly, as part of the position calculation; you actually have to know the speed to get the position, rather than the other way around.
Andrew McGregor
@Andrew: In that case, how does the receiver get the position from a cold start when it is completely stationary?
Daniel Vassallo
@Daniel: The receiver knows, with high precision, the frequencies used by the satellite transmitters. By comparing the known and observed (doppler-shifted) frequencies, the receiver calculates a PRR (pseudo-range-rate) value for each satellite in view and uses that in the position and velocity calculations.
Jim Lewis
And, the receiver downloads a bunch of information from the satellites that tells it where exactly they are (and where they are going to be, a full and precise description of their orbits), and some information about their clocks. It then puts it all together, going backwards from time to speed to distances to position.
Andrew McGregor
Thank you guys! very helpful.
wei
+1  A: 

3) not really a question about android. How to calculate the coordinates of a location, say, 100m away from my current location?

Not really a answer for Your question, but it could be useful for problem You probably try to solve: http://en.wikipedia.org/wiki/Geohash

Maciek Sawicki
Thank you, very interesting hashing.
wei