ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Displaying data in Google Map from 3rd party source

April 28, 2010 2:38pm

Subscribe [2]
  • #1 / Apr 28, 2010 2:38pm

    Adrian Walls

    59 posts

    Hi,

    I am building a property lettings website using EE1.  Part of the site will involve displaying properties available for rent which are retrieved via a REST API from a 3rd party application.  This part is OK but what I then want to do is to generate a Google Map with markers at various zoom levels showing the properties returned by the API.  The API only returns address information (not lat/long) so I would need to geocode the address before it is displayed on the map. 

    I see there are lots of various Google Maps plugins for EE but I don’t expect that there is a “magic” plugin to do what I want.  I don’t really know how to go about doing this and was hoping someone might have done something similar to this in the past and could point me in the right direction.

    Any assistance appreciated 😊

    Wallzy

  • #2 / Apr 28, 2010 7:27pm

    ender

    1644 posts

    You’ll need to geocode the data from the 3rd party API, but you don’t want to do that every time someone loads the page, so you’ll need to store the geocoded info on your server.  I’d recommend creating a new table in your database and handling it there… any time you need to geocode an address just check your local database for the address to see if you’ve already got data for it.  And of course any time you do use the geocoder, store the results in your database cache so you don’t have to look it up again in the future.

  • #3 / Apr 30, 2010 5:26am

    Adrian Walls

    59 posts

    Hi,

    Thanks for your reply.  That sounds like a sensible thing to do.  I started work on this and being a newcomer to EE I am having a few more fundamental issues than this.  I need to generate a search form which will supply parameters to the REST API searching for property.  I a bit stuck as to how to even go about this. 

    I have created a search form but what would I set the action to and how do I then deal with the results that I get back as these have come from outside EE and display these on a page.

    Thanks,
    Wallzy

  • #4 / Apr 30, 2010 9:47am

    ender

    1644 posts

    the first thing to decide is whether you’re going to let the client query the 3rd party API directly via AJAX, or whether you’re going to do it server-side using something like CURL. 

    If you’re going to do it client side you’ll need to request the data be returned in JSON format (if available) and parse it using javascript.  You’ll also need to geocode in javascript.  This would preclude you from storing the cached geocodes on your server, but since geocoding is based on the client’s IP in javascript it might not matter.

    If you’re going to have the client post the form to your server and then query the API from your server via CURL or maybe fopen().  After getting the results of the query you’d likely need to write some PHP code to deal with the results, check the geocode cache for any addresses already geocoded, geocode the rest of them, store those results in the geocode cache, and send it all back to the client.

  • #5 / Apr 30, 2010 11:58am

    dstechroom

    113 posts

    I think Wallzy is asking about how to, within EE, properly handle the form submission (or any custom data exchange).

    This, I believe (although I’m certainly not a super experienced EE developer [yet]), can be accomplished with a custom EE Extension:  http://expressionengine.com/docs/development/extensions.html

    However, I’m not sure which hook to use - perhaps “sessions_start”

    (Or perhaps a plugin would be best?)

    Someone experienced (ender?) Let me know if I’m totally off-base here.

    In any case, some server side code will be necessary if any data is to be stored or retrieved from javascript. Whether AJAX makes a call to the server or whether a form is submitted directly to the server is up to Wallzy’s implementation.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases