# GPS

Al Johnson openmoko at mazikeen.demon.co.uk
Tue Jul 8 19:31:39 CEST 2008

```On Tuesday 08 July 2008, Jay Vaughan wrote:
> > In the link you can see the coordinates and use the spreadsheet
> > attached
> > to his mail to calculate the right x,y,z.
> > This works very well, i've been able to get a fix easy now.
>
> Could you do a step-by-step guide for how to do this, and put it on
> the web somewhere?  I think it would be easy to go from your guide to
> an automatic web-page/script that makes it easier for people to do
> this optimization themselves ..

It would be very easy to take the formulae from the spreadsheet in javascript.
Alternatively you can use it directly in the script if you glue in the calcs
in perl to calculate \$posx, \$posy and \$posz as below. Variable \$posacc is the
estimated accuracy of the supplied location in m.

## WGS84 constants
my \$a;
my \$b;

my \$lat;    # latitude
my \$lon;    # longitude
my \$h;      # height above ellipsiod (m)
my \$e;      # first eccentricity
my \$N;      # Radius of curvature (m)

## set lat & lon in degrees
\$lat = 47.3;
\$lon = 8.5;
## convert to radians for sin / cos to work with

\$h = 0.0;
\$posacc = 150000.0;
# define WGS84 constants
\$a = 6378137.0;
\$b = 6356752.31424518;
# calc intermediate parameters
\$e = sqrt((\$a**2 - \$b**2)/\$a**2);
\$N = \$a / sqrt(1 - (\$e**2 * (sin(\$lat))**2));
\$posx = (\$N + \$h) * cos(\$lat) * cos(\$lon);
\$posy = (\$N + \$h) * cos(\$lat) * sin(\$lon);
\$posz = (((\$b**2 / \$a**2) * \$N) + \$h) * sin(\$lat);

The whole thing needs reimplementing in a redistributable form. I'll be using
it as an excuse to learn python :-) It may take a while since the beer
festival's on for the rest of the week. If anyone else wants to do something
with it I've added links to the various useful resources to the wiki

http://wiki.openmoko.org/wiki/GTA02_GPS

```