Download GPS data from Google Latitude
Latitude Location History KML Export is very interesting. GPS track log is easy to handle geotagging photo than Google Latitude KML data file. I wrote perl program to convert from KML to GPX track log.
- Google Latitude / KML data download
- Google Latitude
https://maps.google.co.jp/locationhistory/b/0
Convert Google Latitude KML data files to GPX track log data files
Example
install DateTime::Format::HTTP
$ cpanm DateTime::Format::HTTP --> Working on DateTime::Format::HTTP Fetching http://www.cpan.org/authors/id/C/CK/CKRAS/DateTime-Format-HTTP-0.40.tar.gz ... OK Configuring DateTime-Format-HTTP-0.40 ... OK Building and testing DateTime-Format-HTTP-0.40 ... OK Successfully installed DateTime-Format-HTTP-0.40 1 distribution installed
convert kml to gpx track log
$ ./latitude_kml2gpx.pl *.kml input: history-05-19-2013.kml output: history-05-19-2013.gpx input: history-05-20-2013.kml output: history-05-20-2013.gpx input: history-05-21-2013.kml output: history-05-21-2013.gpx input: history-05-22-2013.kml output: history-05-22-2013.gpx $
Source Code
#!/usr/bin/perl
# ONO Hiroki onohiroki@cup.com
# http://onohiroki.cycling.jp/comp-google-latitude
# 2013-05-23
use strict;
use warnings;
use Encode;
use utf8;
use open ":utf8";
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";
foreach my $datafile (@ARGV) {
printf "input: %-40s", $datafile;
my $filename_str = $datafile;
$filename_str =~ s/\.kml$//gi;
my $output_filename = $filename_str . ".gpx";
unless ( open KMLFILE, "< $datafile" ) {
die "Cannot open file:$!";
}
unless ( open GPXFILE, "> $output_filename" ) {
die "Cannot open file:$!";
}
print GPXFILE <<'EOS';
<gpx xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
<trk>
EOS
my $time = q{};
my $date = q{};
while (<KMLFILE>) {
if (m#<when>(.*)</when>#) {
$time = $1;
if ( $date eq q{} ) {
$date = $time;
$date =~ s/T.*$//;
print GPXFILE " <name>$date</name>\n";
print GPXFILE " <desc>$date</desc>\n";
print GPXFILE " <trkseg>\n";
}
$time = convert_datetime($time);
}
if (m#<gx:coord>(\S+)\s+(\S+)\s+(\S+)</gx:coord>#) {
print GPXFILE q{ <trkpt lat="} . $2 . q{" lon="} . $1 . q{">};
print GPXFILE
"\n <ele>$3</ele>\n <time>$time</time>\n </trkpt>\n";
}
}
close KMLFILE;
print GPXFILE " </trkseg>\n </trk>\n</gpx>\n";
close GPXFILE;
print " output: ", $output_filename;
print "\n";
}
sub convert_datetime {
use DateTime::Format::HTTP;
my $str = shift;
my $dt = DateTime::Format::HTTP->parse_datetime($str);
$dt->set_time_zone('+0000');
return $dt . "Z";
}
Old version ( does not work now)
- GoogleLatitude.fakeworkflow.zip and kmlwpt2gpx.pl
- Download GPS data from Google Latitude