Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5515 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a database that reps use to enter their visits. I would like to be able to retrieve the distance between postcodes of their visits so that I can produce a reasonable estimate of distance that should have been travelled.

Posted

Given two address, this URL will display the distance between them using Google Maps:

http://maps.google.com/maps?f=d&source=s_d&saddr=STARTING&daddr=ENDING&output=html&oi=slow

where saddr=starting address and

daddr = destination address, both URL encoded.

The attached example will determine the driving distance between two addresses and display it in a dialog box. You may want to add some additional logic to cover an invalid address.

If you don't want to parse the HTML, you can also access Google Maps through its JavaScript API. The webviewer window can be reduced in size if you do not want it visible.

GetDistance.zip

Posted

Excellent technique.

The find distance script breaks when the units are km but it's an easy fix.

Posted

Interesting. For the Australian NSW locations I just tested, Google Maps goes to the Post Office. (For some towns that's about all there is anyway.)

Posted

Vaughan,

You're right, it did not handle km correctly. Also the script will be prone to breaking if Google changes their internal URL's. I used the URL which generates a printable map to come up with that.

A more robust technique is to use the Google Maps API from Javascript. This will expose all API functions to Filemaker so you can show just map, directions, get longitude only, etc. The attached example demonstrates calling a JS function and returning results to FM using the full blown API. This is a more complicated script but a much better technique. I adapted Brian Cray's javascript form example http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/ to FM in the attached example which uses a data url to load the JS into a WebViewer, followed by javascript injected into the URL to execute the function and replace the page contents with the results which can then be read back into FM. This could still use some clean-up (e.g. displays alert boxes on bad addresses, instead of returning an error to FM).

GetDistanceJS_Injection.zip

Posted

Lee,

I'm wondering if the second file doesn't work under OSX? The method I'm using is to load a page into WebViewer which contains a JavaScript function called Showlocation, which accepts address1 and address2 as parameters. The FM script then invokes the function, after page is fully loaded, by using a javascript: in the URL. That causes the script to run and the Google API to be called. The JavaScript variable containing the distance, is then returned to Filemaker, by another javascript injection into the URL, i.e., setting document.content=drivingDistanceMiles, where drivingDistanceMiles is the JavaScript variable. That causes the page source to be set equal to the value of drivingDistanceMiles. It sounds like one or several of these javascript injections might not work on Mac? What happens under OSX if in WebViewer, you go to a URL: javascript:alert("Hello");

It's been about 4 years since I used OSX.

I've used this technique to access libraries that do hashes in JavaScript & return results to Filemaker, and other applications. I suspect this either doesn't work on Macs, or is done differently?

Posted (edited)

I'm sure you are right, OS 10 did change things. However, I'm not knowledgeable in Java, so someone else will have to dig into this for us.

Lee

Edited by Guest

This topic is 5515 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.