Converting Geo-coordinates per Macro

59 views
Skip to first unread message

Martin Hauer

unread,
Apr 30, 2020, 10:31:18 PM4/30/20
to TiddlyWiki
I would like to convert Geo-coordinates with a click on a button in a Tiddler.
The coordinates should be converted from i.e. N 47° 04.624' to 47.077067° and then a Google-Maps link should be created (<a href="http://maps.google.at/maps?q=47.077067+015.437033" target="_blank"> [img[in Google Maps anzeigen|GoogleMaps_Logo_36.gif]] </a>)

Unfortunately I'm a beginner in writing Macros in TiddlyWiki.

The coordinates are stored in fields in the Tiddler like so:

Field1 = N
Field2 = 47
Field3 = 04
Field4 = 624
Field5 = E
Field6 = 015
Field7 = 26
Field8 = 222

Could anyone please help me in solving this problem?

Thanks in advance, Martin

Eric Shulman

unread,
Apr 30, 2020, 11:40:40 PM4/30/20
to TiddlyWiki
On Thursday, April 30, 2020 at 7:31:18 PM UTC-7, Martin Hauer wrote:
I would like to convert Geo-coordinates with a click on a button in a Tiddler.
The coordinates should be converted from i.e. N 47° 04.624' to 47.077067° and then a Google-Maps link should be created (<a href="http://maps.google.at/maps?q=47.077067+015.437033" target="_blank"> [img[in Google Maps anzeigen|GoogleMaps_Logo_36.gif]] </a>)

Field1 = N
Field2 = 47
Field3 = 04
Field4 = 624
Field5 = E
Field6 = 015
Field7 = 26
Field8 = 222

The formula for converted from DMS (degrees,minutes,seconds) to DD (decimal degrees) is: DD = D + M/60 + S/3600

Note that in your example, you are specifying degrees=47 and minutes=4.624  (using two fields to hold integer and decimal portions of the minutes value).

Thus, for D=47, M=4.624, we calculate: DD = 47 + 4.624/60 = 47 + 0.077067

To get this value using TW Math Filter operators, we can write:
{{{ [{!!field2}] [{!!field3}divide[60]] [{!!field4}divide[1000]divide[60]] +[sum[]multiply[1000000]round[]divide[1000000]] }}}
* get the value from field2
* get the value from field3 and then divide by 60
* get the value from field4 and then divide by 1000 to shift the decimal point to the left and then divide by 60
* add these values
* then, to round to 6 decimal places, multiply by 1000000, round to the nearest integer and then divide by 1000000

Thus, to get the latitude and longitude as variables, we would write:
<$vars latitude={{{ [{!!field2}] [{!!field3}divide[60]] [{!!field4}divide[1000]divide[60]] +[sum[]multiply[1000000]round[]divide[1000000]] }}}>
<$vars longitude={{{ [{!!field6}] [{!!field7}divide[60]] [{!!field8}divide[1000]divide[60]] +[sum[]multiply[1000000]round[]divide[1000000]] }}}>

and to construct the desired URL, we can use the title[] and addsuffix[] filters, like this:
<$vars url={{{ [title[http://maps.google.at/maps?q=]addsuffix<latitude>addsuffix[+]addsuffix<longitude>] }}}>

Then, we can display the link this way:
<a href=<<url>> target="_blank"> [img[in Google Maps anzeigen|GoogleMaps_Logo_36.gif]] </a>

Putting it all together:
<$vars latitude={{{ [{!!field2}] [{!!field3}divide[60]] [{!!field4}divide[1000]divide[60]] +[sum[]multiply[1000000]round[]divide[1000000]] }}}>
<$vars longitude={{{ [{!!field6}] [{!!field7}divide[60]] [{!!field8}divide[1000]divide[60]] +[sum[]multiply[1000000]round[]divide[1000000]] }}}>
<$vars url={{{ [title[http://maps.google.at/maps?q=]addsuffix
<latitude>addsuffix[+]addsuffix<longitude>] }}}>
<a href=<
<url>> target="_blank"> [img[in Google Maps anzeigen|GoogleMaps_Logo_36.gif]] </a>
</$vars>
</$vars>
</$vars>

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)



Martin Hauer

unread,
May 1, 2020, 7:55:36 PM5/1/20
to TiddlyWiki
Hi Eric,

many thanks to this solution and the detailled description!
With this it is easy to understand how it is accomplished.

I use TiddlyWiki for so many years now and it is always great to see how many different things can be accomplished with it!

Thanks again!
Reply all
Reply to author
Forward
0 new messages