The GPS functionality now available in HAC apps allows a location determining app to be built that can run continuously either in the foreground or background. The ability of HAC apps to run continuously in the background makes developing such a GPS app quite easy. All it needs is an Android device with either GPS hardware or access to a mobile network that can provide location data.
This post gives a basic overview of GPS location finding and shows the major parts of making your own GPS app with HAC. Fuller details are in the GPS example project included with the HAC installer. There is also both a project and a ready built demo of the GPS app on our Projects web page. The GPS demo app can be installed on an Android device from this link:-
GPS and Locations
Location finding refers to determining one’s latitude and longitude and is usually simply referred to as GPS. There are two forms of location finding, GPS using satellites and Assisted GPS where the location information comes from a Mobile Network.
Satellite GPS is much more accurate than Mobile Network assisted GPS and if several satellites are in view then a fix can be accurate down to a few metres. It takes 3 satellites to give a fix for latitude longitude but 4 satellites to give an altitude fix. However, there are a number of drawbacks with satellite GPS. It can take several minutes to give the first fix and also if the sky is obscured by buildings or rock then the device may fail to see a satellite.
Mobile network or assisted GPS is fast and can usually work indoors. Its drawbacks include network charges plus low accuracy, perhaps few hundred meters, depending upon the location of the mobile network towers.
There are three main steps in getting location information, Firstly to specify the location provider, GPS or Mobile Network. Secondly to specify when location events should be available. Thirdly responding when a location event occurs and processing the information provided.
The demo included with HAC and on our website has three screens, for Network, GPS, and both Network GPS. Below is a screenshot of it running on an Android G1 phone. The green text is a count of how many fixes it has received.
Scripting GPS Demo
As mentioned above there are three steps to acquiring location data and shortened versions of the scripts are shown below. The card displays location values of accuracy, latitude, longitude, altitude and speed using five text controls as shown in the above screenshot. The three scripts are:
1) Specify the location providers, here using both Network and Satellite.
2) Start the location service and request it send update at least very 10000mS and change of 1m.
3) Respond to a GPS data event and process it. The event values indicating a fix is available are 4 for first fix, 5 for location changed and 6 for time changed. This script resides in the GPS event hander.
It is quite easy to make a basic GPS app with HAC as it provides all the basic functionality required. It also provides functions for converting from numeric values of latitude & longitude to degree, minute and second values, plus functions for handling bearings from one location to another.
The best way to understand how this all fits together is to run the GPS project and play around with it. You can also test it to see if the app can truly work while in the background – once you have installed the GPS app, started it and have some location data returning then send it to the back for a while and then later look at the green fix count – it should have increased.
The GPS app demo is here:-http://www.hypernextandroid.com/binaries/apks/GPS%20Satellite.apk
A word of caution though as not all Android devices are equal and the results can depend upon the device hardware and your mobile network.