« MonkeyBread Software … | Home | Real Studio Meeting n… »

Mapping addresses to geo coordinates

Recently a client asked how to map addresses to geo coordinates in Filemaker. He had a web service doing it and wanted to script it in Filemaker with our plugins.

The website is findlatitudeandlongitude.com. If you go there, you see a form where you can enter an address, press a button and have the coordinates shown on the right as longitude and latitude.

In order to script this website in Filemaker, you can load it in our Form utility application (included in Plugins download). There you see there is a form named load_location with a text field "loc". Our form utility shows you the Filemaker calculation line to fill text inside: MBS( "WebView.SetFormInputValue" ; WebViewerRef; "load_location"; "loc"; Value )

Now of course we need a web viewer in Filemaker and give it a name. We use "web" in our examples as the name. So in the examples it's MBS( "WebView.SetFormInputValue" ; "web"; "load_location"; "loc";Latitude Longitude Lookup::Address ).

Next you need to have a little script pause so the web viewer can update. Now if you check the button in the html source (or your favorite web inspector), you discover that it has javascript code calling a function load_address. And instead of using FormSubmit function from our plugin, you need to call that javascript method. So you use this command: MBS( "WebView.RunJavaScript" ; "web"; "load_address(document.load_location.loc.value);") With WebView.RunJavaScript, you run a little javascript piece of code. And the code is what we copy right away from the html source. A lot of websites use that to load information without reloading the page.

Okay. Next we do a pause step, so the website can do the lookup and show information. 2 seconds may be enough. After that pause, we need to get the values. With your favorite web inspector you can see that the latitude is shown in a div with id lat_address in the second text inside that div. To get the value, we use javascript again. In javascript document.getElementById queries the div with the right id. The children() function gives us second child of that node and innerText gives the text inside. To run this javascript, we use WebView.RunJavaScriptReturnTitle as we need the result. So we assign result to document.title and the plugin gives us that value in Filemaker. Final calculation for this looks like this: MBS( "WebView.RunJavaScriptReturnTitle" ; "web"; "document.title = document.getElementById('lat_address').children[1].innerText") For longitude it's the same, just different names.

Well, I hope this example helps you. If you have questions, please don't hesitate to ask questions. Or simply ask us for a kick start help for your website. And don't forget that this breaks as soon as the website changes the layout.

Have fun. Here is the example project: latitudelongitudelookup.fp7.zip

PS: Same can be done in Real Studio with our htmlviewer extensions.
15 12 11 - 00:35