GPS text file converter to Google Earth/Maps
From MikroTik Wiki
- global gpstext [/file get gps.txt contents];
- local longstart [:find $gpstext "longitude" -1];
- local longend [:find $gpstext "\n" $longstart];
- local latstart [:find $gpstext "latitude" -1];
- local latend [:find $gpstext "\n" $latstart];
- local validstart [:find $gpstext "valid" -1];
- local validend [:find $gpstext "\n" $validstart];
- global longitude [:pick $gpstext ($longstart + 12) $longend];
- local degreestart [:find $longitude " " -1];
- local minutestart [:find $longitude " " $degreestart];
- local secondstart [:find $longitude "'" $minutestart];
- local secondend [:find $longitude "'" $secondstart];
- local longdegree;
- local longdegreelink;
- if ([:pick $longitude 0 1] = "W") do={
:set longdegree "-"; :set longdegreelink "W";
} else={
:set longdegree "+"; :set longdegreelink "E";
};
- set longdegree ($longdegree . [:pick $longitude 2 $minutestart]);
- set longdegreelink ($longdegreelink . [:pick $longitude 2 $minutestart]);
- local longmin [:pick $longitude ($minutestart + 1) $secondstart];
- local longsec [:pick $longitude ($secondstart + 2) $secondend];
- local longfract ((([:tonum $longmin] * 6000) + ([:tonum $longsec] * 100)) / 36);
- global newlong ($longdegree . "." . $longfract);
- global newlonglink ($longdegreelink . "." . $longfract);
- global latitude [:pick $gpstext (latstart + 11) $latend];
- set degreestart [:find $latitude " " -1];
- set minutestart [:find $latitude " " $degreestart];
- set secondstart [:find $latitude "'" $minutestart];
- set secondend [:find $latitude "'" $secondstart];
- local latdegree;
- local latdegreelink;
- if ([:pick $latitude 0 1] = "N") do={
:set latdegree "+"; :set latdegreelink "N";
} else={
:set latdegree "-"; :set latdegreelink "S";
};
- set latdegree ($latdegree . [:pick $latitude 2 $minutestart]);
- set latdegreelink ($latdegreelink . [:pick $latitude 2 $minutestart]);
- local latmin [:pick $latitude ($minutestart + 1) $secondstart];
- local latsec [:pick $latitude ($secondstart + 2) $secondend];
- local latfract ((([:tonum $latmin] * 6000) + ([:tonum $latsec] * 100)) / 36);
- global newlat ($latdegree . "." . $latfract);
- global newlatlink ($latdegreelink . "." . $latfract);
- global coordinates ($newlong . "," . $newlat);
- global linkout "http://maps.google.com?q=$newlonglink$newlatlink";
- global kmlout "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://www.opengis.net/kml/2.2\">
<Placemark>
<name>My router</name>
<description>My router's location</description>
<Point>
<coordinates>$coordinates</coordinates>
</Point>
</Placemark>
</kml> ";
- global oldpos;
- if ($oldpos != $coordinates) do={
/file set [/file find name=gps.kml] contents=$kmlout /tool e-mail send to=me@mydomain.com subject="Router move" body="Move to $linkout" file=gps.kml :set oldpos $coordinates;
};