Google Directions From Filemaker

This Filemaker custom function takes two addresses and returns text formatted as a URL to display a Google Map with directions. This can be used to open a URL or Web Viewer window.

Street can be on multiple lines, and can contain unit numbers etc.
State can be abbreviated or full.

If country field is empty, it will default to the country set in DefaultCountry variable.

/*

GoogleDirections ( Street1 ; Suburb1 ; State1 ; Zip1 ; Country1 ; Street2 ; Suburb2 ; State2 ; Zip2 ; Country2 )

*/

Let ( [

// PROCESS ADDRESS 1

DefaultCountry1 = "Australia";

// Remove extra lines
StreetNameTemp1 = If ( PatternCount (Street1;"¶") > 0 and Position(Street1;"¶";1;1)< Length (Street1);Right ( Street1 ; Length ( Street1 ) - Position ( Street1 ; "¶" ; 1 ; 1 ));Street1);

// Remove any unwanted text before the street number
StreetNameTemp1 = Case(
PatternCount(StreetNameTemp1;",")>0;Right(StreetNameTemp1;Length(StreetNameTemp1) - Position (StreetNameTemp1; "," ;1 ;1 ));
PatternCount(StreetNameTemp1;"/") > 0; Right(StreetNameTemp1;Length(StreetNameTemp1) - Position(StreetNameTemp1;"/";1;1));

LeftWords(StreetNameTemp1;1)="Unit" or LeftWords ( StreetNameTemp1 ; 1 ) = "Flat" or LeftWords ( StreetNameTemp1 ; 1 ) = "Level" or LeftWords ( StreetNameTemp1 ; 1 ) = "Suite";Right(StreetNameTemp1;Length(StreetNameTemp1) - Position(StreetNameTemp1;" ";1;2));StreetNameTemp1);

StreetName1 = Trim(RightWords (StreetNameTemp1; WordCount ( StreetNameTemp1 )-1 ));
StreetName1 = Substitute ( StreetName1 ; " " ; "+" );
StreetNumber1 = LeftWords (StreetNameTemp1;1 );

// PROCESS ADDRESS 2

DefaultCountry2 = "Australia";

// Remove extra lines
StreetNameTemp2 = If ( PatternCount (Street2;"¶") > 0 and Position(Street2;"¶";1;1)< Length (Street2);Right ( Street2 ; Length ( Street2 ) - Position ( Street2 ; "¶" ; 1 ; 1 ));Street2);

// Remove any unwanted text before the street number
StreetNameTemp2 = Case(
PatternCount(StreetNameTemp2;",")>0;Right(StreetNameTemp2;Length(StreetNameTemp2) - Position (StreetNameTemp2; "," ;1 ;1 ));
PatternCount(StreetNameTemp2;"/") > 0; Right(StreetNameTemp2;Length(StreetNameTemp2) - Position(StreetNameTemp2;"/";1;1));

LeftWords(StreetNameTemp2;1)="Unit" or LeftWords ( StreetNameTemp2 ; 1 ) = "Flat" or LeftWords ( StreetNameTemp2 ; 1 ) = "Level" or LeftWords ( StreetNameTemp2 ; 1 ) = "Suite";Right(StreetNameTemp2;Length(StreetNameTemp2) - Position(StreetNameTemp2;" ";1;2));StreetNameTemp2);

StreetName2 = Trim(RightWords (StreetNameTemp2; WordCount ( StreetNameTemp2 )-1 ));
StreetName2 = Substitute ( StreetName2 ; " " ; "+" );
StreetNumber2 = LeftWords (StreetNameTemp2;1 )

];

“http://www.google.com/maps?saddr=” & StreetNumber1 & “+” & StreetName1 & “+” & Suburb1 & “+” & State1 & “+” & Zip1 & “+” & If ( IsEmpty(Country1); DefaultCountry1; country1) & “&daddr=” & StreetNumber2 & “+” & StreetName2 & “+” & Suburb2 & “+” & State2 & “+” & Zip2 & “+” & If ( IsEmpty(Country2); DefaultCountry2; country2)
)

This entry was posted in Blog. Bookmark the permalink.

Comments are closed.