GPS Mapping on a Pocket Personal Computer
![]()
This article describes the writing of a program to map GPS locational
information on an Acer n35 Pocket Personal Computer.
The maps used are jpegs of scanned maps.
Simple Basic routines are described for displaying and moving the maps,
for interrogating the on-board GPS unit, and for plotting locations.
- Introduction
- 1. Putting a map on the computer.
- 2. Interrogating the GPS unit.
- 3. Location, Location, Location
- Conclusion
Having acquired a pocket computer with in-built GPS capability I thought it would be useful to be able to use it for general purpose mapping. It had originally been bought for satellite navigation in the car. It came with a program called CoPilot which worked perfectly well for general driving about. No problems. I had chosen a PPC rather than a dedicated SatNav with the thought that I could probably find other uses for a pocket computer, and so it has proved.
The computer is an Acer n35 with GPS, running a Windows operating system. As a walker, it had occurred to me that I might be able to load jpegs of scanned maps and so save carrying folding paper maps about with me. Before long I found it was possible to buy Ordnance Survey maps on CD; a great, if rather expensive innovation. I bought a map or two from suppliers Anquet. These were the Version 1.0 maps which do have provision for running on a pocket computer. The Anquet V1 GPS capability on the PPC is very simple. It allows areas of the map to be downloaded and will show present location on the map but no track logging or anything of a more advanced nature. Later Anquet produced their Version 6 edition which does have the advanced capabilities but which I found I would not run on my Acer. The GPS unit is not recognised at all so I don’t even get positional plotting. Anquet support was not able to help. I came around to thinking that to be able to use maps obtained by scanning paper copies would be more useful. The CD maps, as well as being expensive, are limited in scale and coverage. The GPS system is global. It would be handy if I had a program which would be able to operate anywhere on the globe as long as I had a map for the area. I had seen people wishing for much the same sort of thing in GPS discussion groups. I set about writing my own program.
First there was the problem of a language. Although I have used many different computing languages over the years, these days I tend to use Microsoft’s Visual Basic for the quick knocking together of a program. I have used, and still use from time to time, C++ and Java and so on, but I use these so infrequently that I find myself having to re-learn the syntax each time. Basics are plentiful and tend to be similar syntactically, so I had the inclination to go in that direction. A bit of investigation at the Microsoft web site indicated that there are free programs available with which one might write for the PPC device. These are really aimed at a proper software developer. It seems that embedded Basic and its associated programs are on the way out whilst .NET Compact it seems, is on the way in. It is a bit difficult to sort out what you should and should not have. The programs all seem to be very large with a great deal to them. Fine for a professional developer, less so for me. It was not immediately clear to me what I would need and what I wouldn’t need. I didn’t fancy stuffing my computer full with these programs; 200 MB of Basic with Software Development Kit, Emulators and the like, so I looked around for something simpler. I found two Basics mentioned in discussion groups; GL Basic and NS Basic. Both have download demo versions. The GL Basic seems very games orientated although I am sure it could be used otherwise. The NS Basic seemed more of a possibility so I tried the demo. It is very like a cross between QBasic and a cut-down Visual Basic in form. Programs may be written on the laptop and downloaded to the PPC for execution, although it is also possible to write code directly on the PPC. I found I was able to write most of my mapping program and get it working from the demo version. I believe in paying for what I use so I bought the full version. It is compact and a lot simpler than Microsoft’s development paraphernalia. This is both its advantage and disadvantage. I am quite happy to have that size of file permanently in my computer since I don’t anticipate using it that frequently. It is expensive for what it is, especially when compared with MS’s freebies. The documentation I would describe as adequate as is the Basic. Neither is as full as MS VB. I could imagine people describing this Basic as ‘buggy’. I don’t think it is buggy but I would describe it perhaps as Spartan. You are able to do whatever you are trying to do but it may take a bit of sorting out to get there. Things can be a little off-putting. Syntax errors are seldom in the actual line in which they are reported to be. I would like to be able switch off syntax error reporting. This is not an option. It took me a long while to find out why under some circumstances the Print command did not appear to work. I eventually found the output window was obscured by an overlying form which I wasn’t using, and so on. The one area which does appear to be very good, although I haven’t used it myself, is the support. It is possible to write directly to the software developers who answer questions promptly via a discussion board. However, on with the program.
I do not intend to give the whole of an operating program here but merely to describe the basics behind the program which I wrote and so to help anyone wishing to do much the same as I did.
It seemed to me that there were three basic sections to a GPS mapping program. Firstly getting a map into the computer and being able to move it about, secondly being able to interrogate the GPS unit and so obtain a location, and thirdly, plotting the location on the screen. I wrote these parts of program separately and then combined them to make my own map plotting program. I found it to be surprisingly simple. Here I propose to show simple ‘hows’ for each part and leave the reader to assemble their own finished program. There is no reason why the final program should not include many of the features found in modern GPS units; track and waypoint plotting, route planning and so on, whatever you require. I myself am perfectly happy to use the Geko, discussed in another article on this site, for these functions. It is small, neat and suits me well for my purposes. I could do with longer battery life but that is my only criticism. My Acer program is simply to give me a map when needed and to show my position on that map.
1. Putting a map on the computer.
I made a jpg scan of part of an ordinary map which showed the OS grid lines. I kept the east/west grid lines horizontal; this is important when coming to plot location. Any scan or photo processing program should be able to get the jpg into a suitable size and form. Scans may be joined together to cover a larger area but if the map is too large the scale is changed as it is loaded which is undesirable. You have to work out for yourself suitable map size and scale.
The following is an NS Basic program which will read in a map called ‘Map.jpg’. It is very simple and straightforward. Tapping on the map will relocate its centre on the point tapped. This is just to demonstrate how easily the map may be moved. Dragging would also be possible.
Option Explicit
ShowOKButton True 'Set OK button to close app
On Error Resume Next
Sub Form1_Load
AddObject "PictureBox","Map",0,0,240,268
Map.scalemode = 3
Map.borderstyle = 0
Map.picture = "My Documents/Map.jpg"
End Sub
Sub Map_mousedown(button, shift, x, y)
' Simple move, centre map to stylus tap
Map.ScrollX = 120 - x : Map.Scroll Y = 134 - y
Map.ScrollImage
End SubNote that moving to any edge of the map shows that it repeats. Also it loads to the top left corner, so this is the point I chose as the map origin for later plotting current position.
2. Interrogating the GPS unit.
Again this is very easily done. So easily that it surprises me that the Anquet Version 6 map appears to be unable to do it on my PPC. The NSBasic program below sets a serial port for GPS and on a signal opens the port, reads a block of GPS data, and then closes the port. The illustration shows the how the output appears. The routine as given here should be entered in the Formless format of NS Basic to avoid the Output window being obscured by a form.
![]()
Option Explicit
ShowOKButton True ' Set minimize button to close app
Dim R, F
AddObject "Comm","GPS",0,0,0,0
GPS.CommPort = 8
GPS.Settings = "4800,N,8,1"
GPS.InputLen = 0 ' Read & clear buffer at Input.
Sub Output_Click
R=GetFix
Print R
End Sub
Function GetFix
GPS.PortOpen = True ' Open port.
F= "" : Sleep(2000) ' Clear string & wait,
F = F + GPS.Input ' then collect data.
GPS.PortOpen = False ' Close port.
GetFix=F
End Function
Things to note about this routine. It will return nothing unless the GPS flap on the back of the PPC is open and a signal is being received. Then tapping the screen will return a block of text. This is a single string. To get a location, your program will need to parse the text. Sentences may be separated by looking for a Chr(10) which terminates each. Within each sentence is a set of comma separated fields. The meaning of the sentences and fields may be found by searching for NMEA (National Marine Electronics Association) protocols on the Internet. The sentence which is of most concern to us starts $GPGGA; this is a ‘fix’ string. The following is a typical fix string,
$GPGGA,180310.529,5137.3034,N,00011.6648,W,0,00,50.0,129.9,M,47.0,M,0.0,0000*59The first six fields in this string are needed. The first is the identifier; this always starts with a $. The second is a measure of time - UTC (Co-ordinated Universal Time, a high-precision atomic time standard). The third is latitude given as ddmm.mmmm (d degrees, m minutes). The fourth indicates the hemisphere (N or S). The fifth is longitude in form dddmm.mmmm and the sixth indicates East or West of the 0 meridian. Other fields are of interest: they include numbers of satellites received, accuracy of measurements, height information and a sentence checksum. The other sentences all contain interesting data like the condition of the satellites and so on, but here we are concerned only with, to coin a phrase, getting a fix.
3. Location, Location, Location
This is by far the most complex part of the operation. The fix obtained from the GPS unit is in latitude and longitude. These are points on imaginary curved lines on the surface of a spheroid, the earth. The map on which we wish to plot our position is flat and described on a square grid; the Ordnance Survey grid. Obviously distortion must be involved. We have to translate the latitude and longitude into the OS square grid easting and northing and then finally, into x and y, the number of pixels displacement from the origin of the screen representation of our map. The first translation is made possible by a set of equations available from the Ordnance Survey. Full discussion is at the Ordnance Survey web site The equations used here are to be found in the appendices B and C. The program below uses those equations to convert latitude and longitude, expressed as decimal degrees, into an easting and northing measured in metres from the O.S. false origin close by the Scilly Isles. Note that longitudes west of the zero meridian are expressed as negative decimal degree values before conversion; those to the east are positive. Again this is a routine which should be entered in the Formless format of NS Basic.
Option Explicit
ShowOKButton True 'Set minimize button to close app
On Error Resume Next
' Set Conversion Vars & Parameters
Dim Pi:Pi=4*Atn(1)
Dim n0, e0, f0, phi0, lambda0, a, b, e2
Dim phi, lambda
Dim n, v, ro, nu2,M
Dim I, II, III, IIIa, IV, Va, VI
n0=-100000:e0=400000:f0=0.9996012717
phi0=49/360*2*Pi:lambda0=-2/360*2*Pi
a=6377563.396:b=6356256.91:e2=(a*a-b*b)/(a*a)
' Gen Prog starts
Dim x1, y1
' 52:39:27.251 N 1:43:4.5177 E ' O.S. Appendix Example
Conv 52.65756972, 1.717921583 ' O.S. example in decimal degrees
' E 651409.903m N 313177.270m O.S. result
' 651409.906278459m 313177.20524938m Conv result (diff is 2.5" in 190 miles)
Print x1, y1
Sub Conv (Lat,Lng) ' DecDeg To N E OS grid metres
phi = Lat/360*2*Pi : lambda = Lng/360*2*Pi
n = (a-b)/(a+b)
v = a*f0*((1-e2*Sin(phi)*Sin(phi))^-0.5)
ro = a*f0*(1-e2)*((1-e2*Sin(phi)*Sin(phi))^-1.5)
nu2 = v/ro-1
M = b*f0*( _
(1+n+5/4*n*n+5/4*n*n*n)*(phi-phi0)- _
(3*n+3*n*n+21/8*n*n*n)*Sin(phi-phi0)*Cos(phi+phi0)+ _
(15/8*n*n+15/8*n*n*n)*Sin(2*(phi-phi0))*Cos(2*(phi+phi0)) - _
35/24*n*n*n*Sin(3*(phi-phi0))*Cos(3*(phi+phi0)))
I = M + n0
II = v/2*Sin(phi)*Cos(phi)
III = v/24*Sin(phi)*(Cos(phi)^3)*(5-(Tan(phi)^2)+9*nu2)
IIIa = v/720*Sin(phi)*(Cos(phi)^5)*(61-58*(Tan(phi)^2)+(Tan(phi)^4))
IV = v*Cos(phi)
Va = v/6*(Cos(phi)^3)*(v/ro-(Tan(phi)^2))
VI = v/120*(Cos(phi)^5)*(5-18*(Tan(phi)^2)+(Tan(phi)^4)+14*nu2-58*(Tan(phi)^2)*nu2)
y1 = I+II*((lambda-lambda0)^2)+III*((lambda-lambda0)^4)+IIIa*((lambda-lambda0)^6) ' northing
x1 = e0+IV*(lambda-lambda0)+Va*((lambda-lambda0)^3)+VI*((lambda-lambda0)^5) ' easting
End Sub
With these three sections of program it is now possible to connect them together into a simple location program. I am not proposing to give details because the actual arrangement should be very much an individual choice, I will however describe the basic requirements.With the map loaded, the location of the top left corner, expressed in decimal degrees, should be run through routine Conv to find the origin as a northing and easting pair. These are saved in my program as y0, x0. Next the GPS is interrogated and from the results, the lat long location is deduced. This is converted to decimal degrees and put through the Conv routine to give N E pair for the current location, y1, x1.
The map may then be centred on the current location by computing the number of pixels to scroll the map into position. The computations required are of the form,
Map.ScrollX=120-(x1-x0)*factor1 The constants 120 and 134 are to put the location at the mid point of the 240 x 268 pixel screen. The factors 1 and 2 are required to convert the displacements, measured in metres, into pixels. They depend on the map scale used. The way to calculate these factors is to find the width and height - in metres, which your screen shows of the map. Each of these figures is then divided into its corresponding number of pixels. There is a variety of ways in which this may done and it can be a bit tricky so I’ll describe one possible way. This is for factor1. With the map loaded on your PPC pick a point on the left edge of the screen map and a corresponding point on the right edge. Go to your original map and find those two locations. Measure accurately the distance between them. From the kilometres scale at the bottom of the map, re-interpret the measurement as a number of metres. Divide 240 by this figure and you will have factor1, the number of pixels per metre for the horizontal displacement. Repeat the process on the vertical dimension for factor2. Put a bit of thought into obtaining these figures as accurately as you possibly can because on them will rest the accuracy of your location plot. Of course, accuracy with the measurement of the origin, the x0, y0 values, is also vital. Should the map be changed for another of a different scale, at any time, these factors will need to be recomputed.
Map.ScrollY=134-(y0-y1)*factor2Once the basic programme is operating, all sorts of enhancements are possible. On mine I have sacrificed a part of the screen area to put on a status bar which shows the condition of the GPS. It tells whether it is receiving or not, whether it is awaiting a fix, or the actual latitude and longitude if it indeed has a fix. I have also overlaid the screen centre with a small red cross for clarification of the actual present location.
Home Page