#!/usr/bin/perl # Given coordinates, outputs a GPX file suitable for use with GPX # Spinner and/or EasyGPS. # Usage: # http://server/cgi-bin/coords.pl?lat=12.345&long=34.567&name=FileName # # OR # http://server/cgi-bin/coords.pl?lat=12d34.567long=-34d56.985&name=FileName # # Degrees south or west should be indicated by a - sign in front of # the coordinates. Other formats of coordinates are not supported, and # behavior is indefined. Patches welcome. # Released under the HJTI license use Geo::Gpx; use Geo::Cache; use CGI::Lite; my $cgi = new CGI::Lite; my %form = $cgi->parse_form_data; my $name = $form{name}; my $long = $form{long}; my $lat = $form{lat}; # long = 37d51.353 for ($lat, $long) { if (/d/) { my ($deg,$min) = split /d/; $deg =~ s/^(-)//; $_ = $deg + $min/60; # Is modifying the loop var evil? $_ *= -1 if $1; # Muhahahah } } my $wpt = Geo::Cache->new( name => "$name", lon => "$long", lat => "$lat", desc => "$name", ); my $gpx = Geo::Gpx->new( $wpt ); my $fname = $name; $fname =~ s/[^a-zA-Z]//g; if ($form{format} eq 'loc') { my $loc = $gpx->loc; print "Content-type: application/loc\n"; print "Content-Disposition: inline;filename=$fname.loc\n\n"; print $loc; } else { my $xml = $gpx->xml; print "Content-type: application/gpx\n"; print "Content-Disposition: inline;filename=$fname.gpx\n\n"; print $xml; }