Jump to content
Server Maintenance This Week. ×

Geocoding using Google Maps API and Web Viewer


DFehrenbach

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

Recommended Posts

I am trying to obtain lat and long info from google maps api to store into a Contact record in FM. I have successfully formatted a web viewer to return the info into an xml file formatted into the web viewer. My questions is how to I get FM to parse the lat and long info from the resulting web viewer to place into the database?

Link to comment
Share on other sites

The returned XML likely looks like this:

long,lat,altitude

First assign a variable $HTML = GetLayoutObjectAttribute( "My_WebViewer" ; "content" )

{This assumes your web viewer is named 'My_WebViewer')

Then use the POSITION function to find the starting position of the XML:

$Start = Position($HTML,"",1,1")+Length("")

$End = Position($HTML,",",$Start,1)

$Longitude=Middle($HTML,$Start,$End-$Start)

$Start = $End + 1

$End = Position($HTML,",",$Start,1)

$Latitude=Middle($HTML,$Start,$End-$Start)

Alternately you can use Scriptmaster and XPath to parse it, or import it directly into Filemaker.

I omitted extraction of the altitude above because I think Gooogle still has all altitudes set to zero.

Link to comment
Share on other sites

Hello DFehrenbach,

We are thinking alike it seems. Here is a FileMaker utility that I was working on this week to take advantage of Google's Map API. It converts a typical address to its GIS data equivalent (lat,lng). It then plots the location with a Marker/Pin on a fixed size Google Map. The Map settings can be configured to your custom settings. This still needs improvement, such as adding the Zoom and Pan functions directly onto the displayed map in the Web Viewer (hint: jQuery).

You can pull the script apart to get to the functions I used to get just the Lat and Lng from Google. The process involves grabbing the content from the Web Viewer and then capturing the line that 'Lat' and 'Lng' appear on. This is designed exclusively for Google's XML output, not JSON.

You can download the attached file here. If you are not a member then just contact me using my Email in my profile.

Best Regards,

Charlie

FMBiz.net

Google_GIS_api.zip

Edited by Guest
Link to comment
Share on other sites

  • 3 months later...

Would you still have to obtain a key if you didnt have a website? I would like to make a distance finder based off of the top result on google maps direction search as opposed to a lat/lon " as the crow flies" distance finder.

I can't seem to find one that works the way Im thinking so I can dissect and figure out what makes it tick... any ideas?

I did make a web viewer that pulls the desired info now but getting that info takes about 3 steps, I have to do a manual entry and the page doesnt look good with what Ive designed...

Im not being too picky am I...

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • Newbies

Hello Charlie,

I downloaded your api and it works great.

I have a question though, my database list contain a 'address','city','postal_code' & 'country' field, however for some records I do not dispose of the 'postal_code'.

How should I modify your script so that the 'postal_code' is also parsed from the obtained xml?

Thanks for your assistance.

Sammy

Hello DFehrenbach,

We are thinking alike it seems. Here is a FileMaker utility that I was working on this week to take advantage of Google's Map API. It converts a typical address to its GIS data equivalent (lat,lng). It then plots the location with a Marker/Pin on a fixed size Google Map. The Map settings can be configured to your custom settings. This still needs improvement, such as adding the Zoom and Pan functions directly onto the displayed map in the Web Viewer (hint: jQuery).

You can pull the script apart to get to the functions I used to get just the Lat and Lng from Google. The process involves grabbing the content from the Web Viewer and then capturing the line that 'Lat' and 'Lng' appear on. This is designed exclusively for Google's XML output, not JSON.

You can download the attached file here. If you are not a member then just contact me using my Email in my profile.

Best Regards,

Charlie

FMBiz.net

Link to comment
Share on other sites

  • 4 weeks later...

Here is a FileMaker utility that I was working on this week to take advantage of Google's Map API. It converts a typical address to its GIS data equivalent (lat,lng).

I am only focusing on obtaining the GIS data. Your solution works beautifully in terms of speed. But, why is the data generated in your solution different from that of what is retrieved from Google Earth?

For example,

1600 Pennsylvania Ave NW, Washington, DC returns:

38.897673, -77.036517 in Google Earth

38.8945301, -77.0396646 in your solution.

They are close, but your solution is off a bit, while Google Earth's seems to be dead on.

Additionally, the Empire State Building is at 350 5th Avenue, New York, NY

40.748070, -73.984959 in Google Earth

40.7449224, -73.9881066 in your solution

The discrepancy here seems to be a bit further off. But, again, Google Earth is dead on.

Why wouldn't the solutions be generating the same GIS Data??

Link to comment
Share on other sites

I dug into this issue and found out what was happening.

Essentially Google returns three different Long/Lat coordinates with are used for different purposes. The coordinates that are returned from Google Earth, are actually returned by the API, but FMbiz.net's solution was grabbing a different set.

I edited the file to return the same values Google Earth would return. Also, I edited the script to return the phrase "Approximate" for when the address is not specifically found in Google's database and returns an approximate value.

Here it is for anyone that wants it.

Google_GIS_api.fp7.zip

Link to comment
Share on other sites

  • 1 month later...

I wonder why so many people are willing to mess with parsing XML from web viewer - instead of taking advantage of Filemaker's ability to import XML data.

Would importing the XML require a XSLT file?

I ask since XSLT is being deprecated by FIleMaker Inc.

If not, importing the XML sounds good... but how is it done?

Thanks,

ft.

Link to comment
Share on other sites

Would importing the XML require a XSLT file?

Yes.

I ask since XSLT is being deprecated by FIleMaker Inc.

No, it's not. It's the XSLT API for Custom Web Publishing that will be discontinued.

If not, importing the XML sounds good... but how is it done?

That's a rather wide question...

Link to comment
Share on other sites

Thanks for the clarifications and sorry for the wide question.

I guess my question should have been, "Where is the best place for an xslt newbie to learn how to make a xslt file, specifically for importing xml results from Google Maps API v3?"

Many thanks,

ft.

Link to comment
Share on other sites

I am afraid I don't have a really good answer to that either - see:

http://fmforums.com/forum/topic/77590-export-field-contents-to-web-page-with-php/page__p__363905#entry363905

If you have an example of the XML response, why don't you post it here - perhaps it's not that difficult.

Link to comment
Share on other sites

Thanks for the consideration.

Here is the xml output of a query:

<GeocodeResponse> 

<status>OK</status>

<result>

<type>street_address</type>

<formatted_address>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</formatted_address>

<address_component>

<long_name>1600</long_name>

<short_name>1600</short_name>

<type>street_number</type>

</address_component>

<address_component>

<long_name>Amphitheatre Pkwy</long_name>

<short_name>Amphitheatre Pkwy</short_name>

<type>route</type>

</address_component>

<address_component>

<long_name>Mountain View</long_name>

<short_name>Mountain View</short_name>

<type>locality</type>

<type>political</type>

</address_component>

<address_component>

<long_name>San Jose</long_name>

<short_name>San Jose</short_name>

<type>administrative_area_level_3</type>

<type>political</type>

</address_component>

<address_component>

<long_name>Santa Clara</long_name>

<short_name>Santa Clara</short_name>

<type>administrative_area_level_2</type>

<type>political</type>

</address_component>

<address_component>

<long_name>California</long_name>

<short_name>CA</short_name>

<type>administrative_area_level_1</type>

<type>political</type>

</address_component>

<address_component>

<long_name>United States</long_name>

<short_name>US</short_name>

<type>country</type>

<type>political</type>

</address_component>

<address_component>

<long_name>94043</long_name>

<short_name>94043</short_name>

<type>postal_code</type>

</address_component>

<geometry>

<location>

<lat>37.4217550</lat>

<lng>-122.0846330</lng>

</location>

<location_type>ROOFTOP</location_type>

<viewport>

<southwest>

<lat>37.4188514</lat>

<lng>-122.0874526</lng>

</southwest>

<northeast>

<lat>37.4251466</lat>

<lng>-122.0811574</lng>

</northeast>

</viewport>

</geometry>

</result>

</GeocodeResponse>

Many thanks,

ft.

Link to comment
Share on other sites

And you want to import...?

I would like to import the short_name of each address_component into a specific FileMaker field.

For example (taken from previous xml data sample), I'd like to import the value 94043 into my postcode field from the following.

<address_component>

<long_name>94043</long_name>

<short_name>94043</short_name>

<type>postal_code</type>

</address_component>

Many thanks,

ft.

Link to comment
Share on other sites

  • 3 months later...
  • 2 weeks later...

Thanks for the clarifications and sorry for the wide question.

I guess my question should have been, "Where is the best place for an xslt newbie to learn how to make a xslt file, specifically for importing xml results from Google Maps API v3?"

Many thanks,

ft.

ft

XML/XSLT is NOT deprecated for import/export! My book is not specific to any XML schema as it can be different for each person and your database can be different. However, it's a great source for learning the XSLT/XPath vocabulary necessary for importing/exporting xml with FileMaker. It has "FM 6" in the title, but other than a few screen shots (and the chapter on web publishing), it's the SAME for "FM 7-11". :)

http://www.amazon.com/Beverly-Voth/e/B001K8NYW2

Link to comment
Share on other sites

  • 4 months later...
  • Newbies

I've downloaded the file and it seems to work...to a point and then the API seems to cut it off. I have ~12,000 adddresses that I'd like to geocode. Does anyone know of an alternate method. I've tried geobatch.com but I can seem to retrieve the lat/long.

Link to comment
Share on other sites

  • 1 month later...
  • Newbies

Hello,

I've implemented the revised sample file that AgentSka provided above. However, I'm running into an issue pulling latitude when there is an instance of a word in one of the address fields containing "lat" in it. For example, the city "PaLATine". Because it contains "lat" the script sees this and tries to pull the latitude number beginning at the city Palatine. I'm clueless when it comes to HTML and i was wondering if anyone else had run across an issue like this.

Let me know, thanks!

Link to comment
Share on other sites

  • 8 months later...

Hi to all. in the solution here some time i get a result like this.

 

 

OK street_address Yigal Alon 7, Kiryat Motzkin, Israel 77 street_number Yigal Alon Yigal Alon route Kiryat Motzkin Kiryat Motzkin locality political Israel IL countrypolitical 32.8423163 35.0821596RANGE_INTERPOLATED 32.8409612 35.080805032.8436591 35.0835030 32.8423040 35.082148432.8423163 35.0821596

and it only give me back the result of " 35.080805" 

 

and some time i get back the both Parameter and the result is like this.

 

 

OK locality political Afula, Israel Afula Afula localitypolitical Israel IL country political 32.610493035.2879220 APPROXIMATE 32.5744489 35.247241032.6407691 35.3739620 32.5744489 35.247241032.6407691 35.3739620

 

  Here i get 32.5744489 & 35.247241.

 

Can some help please ?

Link to comment
Share on other sites

This topic is 4135 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.