:: Forums :: Discussions :: Locator
 
<< Previous thread | Next thread >>
Caching and GoogleMapsAPI class
Moderators: nlstart
This thread is now closed
Author Post
bugrain
Registered Member #322
Joined:
Posts: 7
Well, I thought Locator was perfect for my site, then I realised I really needed it built in to one of my plugins that I'm writing, so have done that instead. Thanks for the code, though, saved me a lot of effort.

Anyway, whilst I was doing this I added some proper e107 style caching to the GoogleMapAPI class, here's the changes I did:

    /**
     * get the geocode lat/lon points from cache for given address
     * 
     * @param string $address
     */
    function getCache($address) {
      global $e107cache, $pref;
      if ($value = $e107cache->retrieve($address, false, true)) {
         return unserialize($value);
      }
      return false;
    }
    
    /**
     * put the geocode lat/lon points into cache for given address
     * 
     * @param string $address
     * @param string $lon the map latitude (horizontal)
     * @param string $lat the map latitude (vertical)
     */
    function putCache($address, $lon, $lat) {
      global $e107cache, $pref;
      if(strlen($address) == 0 || strlen($lon) == 0 || strlen($lat) == 0) {
         return false;
      }
      
      $value = array("lon" => $lon, "lat" => $lat);
      $e107cache->set($address, serialize($value), true);
           
      return true;
    }


The final 'true' parameter on the set() and retrieve() calls forces the caching and ignores the e107 preference for caching turned on/off. May be better to add this as a preference to allow caching only for Locator.

Also, I'm considering putting this class in to e107 Helper (updated for an e107 environment of course) and allowing setting global preference values for any plugin that wants to use a Google map. let me know if this is any use to you.
Back to top
 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System