BashScripts.org
http://bashscripts.org/forum/

Extract Longitude/Latitude
http://bashscripts.org/forum/viewtopic.php?f=15&t=1182
Page 1 of 1

Author:  BrianUK [ Tue Aug 31, 2010 5:15 am ]
Post subject:  Extract Longitude/Latitude

I'm using gpxlogger to output my current location

on startup it outputs

Code:
<?xml version="1.0" encoding="utf-8"?>
<gpx version="1.1" creator="navsys logger"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.topografix.com/GPX/1.1"
        xsi:schemaLocation="http://www.topografix.com/GPS/1/1
        http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
  <name>NavSys GPS logger dump</name>
  <author>Amaury Jacquot</author>
  <copyright>BSD or GPL v 2.0</copyright>
</metadata>
<trk>
  <trkseg>
   <trkpt lat="11.111111" lon="-2.222222">
    <ele>nan</ele>
    <time>2010-08-31T11:10:41Z</time>
    <fix>2d</fix>
   </trkpt>


I would like to extract <trkpt lat="11.111111" lon="-2.222222"> ie whatever numbers/characters are between "" in lat= and lon=

so it outputs

http://maps.google.com/maps?q=11.111111,-2.222222

Author:  DarthWavy [ Tue Aug 31, 2010 6:05 am ]
Post subject:  Re: Extract Longitude/Latitude

I don't know anything about gpxlogger but from the info you supplied the following may work;

Code:
gpxlogger | awk -F \" '/<trkpt/ { print "http://maps.google.com/maps?q="$2","$4 }'


Author:  choroba [ Tue Aug 31, 2010 7:28 am ]
Post subject:  Re: Extract Longitude/Latitude

Code:
sed -rn '/<trkpt lat="/{s%.* lat="([^"]+)" lon="([^"]+)">.*%http://maps.google.com/maps?q=\1,\2%;p}'

Author:  BrianUK [ Wed Sep 01, 2010 8:14 am ]
Post subject:  Re: Extract Longitude/Latitude

Thanks for that i've just managed to break the box I was going to test it on so once rebuilt will let you know.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com