GPS Text Output file import to Google Earth or Google Maps.

going to try and now link it so i can push it out to the guys on the ground IPhone, probably maps.Google as the IPhones don’t load kml/kmz files…

If you read normis’ post carefully, you will see how I tested the coordinates. I did not build a kml file. I built a Google maps link instead. Doesn’t need a kml file.

arr yes i see,
could we include that in the email as well, like in the body ??

That is easy, but give me a bit to get the code together. I deleted the Google Maps link generator code when I completed the kml file generator code. I have a business to run while I am not on the forum. :wink:

ADD: I must build coordinates that use ‘E’, ‘W’ and ‘N’, ‘S’, instead of ‘+’ and ‘-’, but keep the decimal format.
Here is yours from my browser history.
http://maps.google.com/?q=E148.1636S23.5552

Here is the new code. Puts a Google Maps link in the email instead of the coordinates. Should be copy-and-paste into the script editor and save as gps (I did anyway). . Change the email address!

: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;
};

I changed a couple minor things too. Now it doesn’t write to the file if it isn’t going to send the email. Saves write cycles on the memory.

Check back for changes.

EDIT: Changed ‘+’ and ‘-’ to show correct hemisphere in the kml file. :laughing:

great,it worked a treat on the Iphone once i remove the "moved to " part
Also I changed the
:if ([:pick $longitude 0 1] = “W”) do={
:set longdegree “+”;
:set longdegreelink “W”;
} else={
:set longdegree “-”;
:set longdegreelink “E”;

to

:if ([:pick $longitude 0 1] = “E”) do={
:set longdegree “+”;
:set longdegreelink “E”;
} else={
:set longdegree “-”;
:set longdegreelink “W”;

as the link was in the ocean somewhere lol

Made a change, then removed it. Before I change it, do you mean the ‘+’ and ‘-’ is reversed on the coordinates in the kml file?

yer the KML file had the cord of 148° 9’48.96"W instead of 148° 9’48.96"E
so i changed the
:if ([:pick $longitude 0 1] = “W”) do={ <---- to a E
:set longdegree “+”;
:set longdegreelink “W”; <---- to a E
} else={
:set longdegree “-”;
:set longdegreelink “E” <----- to a W

OK, I changed the ‘-’ and ‘+’ in the code. Same result as switching ‘E’ and ‘W’. Didn’t notice when I converted from Google Maps to the kml file. Now it is in the correct hemisphere! :laughing:

works like a charm :smiley: many many thanks

Now in the wiki.
http://wiki.mikrotik.com/wiki/GPS_text_file_converter_to_Google_Earth/Maps

ADD: If you are interested, check back at the wiki now and then. I still must add the position valid check.

a very much needed wiki,thanks Tim

Wow, incredible piece of work Tim!
That has a great many app. possibilites.

I’m waiting for Shark Week :open_mouth:
Any idea which day of the week it shows you on?
My slingbox is down right now, as I don’t have TV on my boat (office). I do have internet, All I need.
T

The Discovery Channel Guide show it scheduled for August 7th at 10 am Eastern/Pacific.
The moral of the story: If you go to the beach, don’t swim out too far!
I rescued three near-drowning victims over the last several years also, but unlike the shark attack victim, all those survived.

FYI - just a small note, if the GPS unit losses power or is unplugged the RB retains the last set of Lat/Longs its received.
Look at the time and you will notice that its not moving…
Hopefully this could be looked at in a future firmware upgrade as this can be misleading ?? Normis any thoughts??

The global variables are reset after a power failure. The files are not.

If you want to avoid receiving an email about moving after a power failure, you should modify the script to check the variable oldpos for an entry. If oldpos is blank (length = 0), the router has been powered down since the last check.

ADD: I thought it was a good idea to let the code send the email if there was a power fail. Since it doesn’t remember where it was last check, then it did ‘move’ from where it thought it was (nowhere).

About to deploy around 50 of these units over different sites, I will let everyone know the outcome…
Next side of this little project would be to have a static map running on the dude server and somehow getting it to probe each unit and update is location…anyone got any ideas on if this could be done ?

that would be cool any updates on this?

Just conducted my first mobile test and all works very well…
had to make some small changes but the results are great…

Tim,

Would you be willing to modify the code to use Openstreet Maps instead of Google Maps? The reason being Google charges 10,000 dollars to use their maps for asset tracking.

Mike