Implementation Details


The GPS location sensing code will run as a service in the background. The application will have an activity to start/stop this service. We also have another activity which displays the embedded Map View for overlay. When the location service is notified of a location change by the Location Manager class, it sends a message to the centralized server. We have decided to use simple datagram messaging (UDP) between the Phone, and the centralized server since updates regarding the position are just couple of bytes, and any other method such as HTTP Post would involve setting up of a TCP connection which will is a time consuming process for just transmitting 5-10 bytes of information. There are two types of message formats, which are as follows:

Location update from the phone

Android ID GPS Coordinate-X GPS Coordinate-Y

Location update from the server(for overlay)

Location Name Average service time GPS Coordinate-Y

Server Rules

Every time the server receives a message from a mobile device it timestamps the message and runs a set of rules on the message. These rules are as below:

  • Was the device at the same location previously ?
  • If yes accrue the time spent at that location.
  • If not and the device has moved to a new location check the accrued time spent at the previous location if it the time spent is above a certain (configurable) threshold, locate the service record for that particular location, and average this new time spent against the historical records this can be done by taking a weighted average as follows. New Average= Historical Average(Alpha) + New observation(1-Alpha) This parameter Alpha acts as a knob to control how much relevance the new readings are given compared to the recorded averages.
  • Also if customer has entered new location check if the new location is within a point of interest, if yes fetch service record for this new location.

Server Records Storage

The server uses the Google App Engine Data base to store these data values and they are accessed using the Google Query Language (GQL). We maintain two tables – one to record the previous position of the device and one to store the average service time for a location. The record formats are as indicated below.

Android ID Location Timestamp at location

Location Average service time at location