pdestefanis/Ushahidi_Android — Issue #13: Add Report: Clarify the logic for resolving current location
Author: pdestefanis
Created: 2012-01-20 15:28:54+00:00
State: open

Add Report: Clarify the logic for resolving current location, we need to know exactly which location provider is being used, and when.

This example assumes that the default_latitude (Issue #7), default_longitude (Issue #7), location_timeout (Issue #XXX), and location_tolerance (Issue #XXX) have been set.

If in doubt, get in touch with Pablo

See following example:

Variables in settings file:
Timeout (default 60 seconds)
Default_Latitude (default -89.2216)
Default_Longitude (default 13.69947)
Tolerance = 2

You can use any names for the functions. This is just pseudocode, and it’s not meant to tell you how to code, just show you the logic

Use_GPS()
If ! isProviderEnabled(GPS_PROVIDER)
Use_Network()
else
While T < TIMEOUT
getLastKnownLocation(GPS_PROVIDER) // only wait for TIMEOUT seconds. If timeout expires, the call Use_Network()
endif

If found() //before the timeout
Return (Latitude, Longitude)
Else
No_Location()
Endif

Return (Latitude, Longitude)

Use_Network()
If ! isProviderEnabled(NETWORK_PROVIDER)
No_Location()
Else
getLastKnownLocation(NETWORK_PROVIDER) // this loads Latitude and Longitude variables (your names may vary)
endif

If ! ( Latitude and Longitude are within Tolerance degress of Default_Latitude and Default_ Longitude) // ie: ( abs(Default_Latitude) – Tolerance ) < abs(Latitude) < ( abs(Default_Latitude) +Tolerance ) // same for longitude
No_Location() /// will it make sense to call getLastKnownLocation(NETWORK_PROVIDER) again, and recheck if < Tolerance?
endif

Return (Latitude, Longitude)

Review the use of getLastKnownLocation or requestLocationUpdates