On Apr 13, 2007, at 3:08 AM, David McQueen wrote:

If the zip data you have has latitude and longitude also, you can set up so that when a person is selected or a zip code entered, the lat. and long. go to globals causing a distance calc in each of the other person's records. You can then find distance less than or you can approximate by changing the distance to time using your own factor.

[If I have more time I'll create a simple example. Right now mine is embedded in a larger database. I can do 5 records per second using this method. I can get more per second using AppleScript and "curl", but the below is cross-platform.]

It is also possible to obtain the latitude and longitude using a "geocode" web service. The one I've been using is Yahoo, as it's fairly easy to use, and seems to be lenient if the address is not perfect. It also returns the level of precision it was able to use; address, street or zip.

You can then use a custom function to calculated the distance. There are a couple at:
briandunning.com/filemaker-custom-functions/list.php

You need to get an ID from the Yahoo Maps API page, and there is a limit of 5000 requests per day.

You can get the data directly into FileMaker using a URL request (from a FileMaker calculation) in an XML Import step:

http://api.local.yahoo.com/MapsService/V1/geocode? appid=YourYahooAPI_id_here&street=1728+Meade+Ave&city=San +Diego&state=CA&zip=92116


The xml returned looks like this:

<?xml version="1.0"?>
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http:// api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
  <Result precision="address">
    <Latitude>32.757337</Latitude>
    <Longitude>-117.147088</Longitude>
    <Address>1728 MEADE AVE</Address>
    <City>SAN DIEGO</City>
    <State>CA</State>
    <Zip>92116-3930</Zip>
    <Country>US</Country>
  </Result>
</ResultSet>


The xsl stylesheet to transform it for import into FileMaker looks like this (I'm getting the zip code also, in case it's missing in FileMaker):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
xmlns:yah="urn:yahoo:maps" exclude-result-prefixes="yah">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
        <xsl:template match="/">
                <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult";>
                        <ERRORCODE>0</ERRORCODE>
                        <PRODUCT BUILD="" NAME="" VERSION=""/>
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT="h:mm:ss a"/>
                        <METADATA>
                                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="LL_precision" 
TYPE="TEXT"/>
                                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Latitude" 
TYPE="NUMBER"/>
                                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Longitude" 
TYPE="NUMBER"/>
                                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Zip4" 
TYPE="TEXT"/>
                        </METADATA>
                        <RESULTSET FOUND="">
                                <xsl:for-each select="yah:ResultSet/yah:Result">
                                        <ROW MODID="0"  RECORDID="">
                                                <COL>
                                                        <DATA>
                                                                <xsl:value-of 
select="@precision"/>
                                                        </DATA>
                                                </COL>
                                                <COL>
                                                        <DATA>
                                                                <xsl:value-of 
select="yah:Latitude"/>
                                                        </DATA>
                                                </COL>
                                                <COL>
                                                        <DATA>
                                                                <xsl:value-of 
select="yah:Longitude"/>
                                                        </DATA>
                                                </COL>                          
                  
                                                <COL>
                                                        <DATA>
                                                                <xsl:value-of 
select="yah:Zip"/>
                                                        </DATA>
                                                </COL>                          
                                  
                                                </ROW>
                                </xsl:for-each>
                        </RESULTSET>
                </FMPXMLRESULT>
        </xsl:template>
</xsl:stylesheet>



Fenton Jones
FileMaker Development
1728 Meade Ave
San Diego, CA 92116
619-692-1529
http://fentonjones.com

Reply via email to