Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
klaftertief committed Mar 8, 2013
2 parents f1f38a2 + a96b3e3 commit 5a1eb1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 3 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
</author>
</authors>
<releases>
<release version="1.0.1" date="2013-03-08" min="2.3">
- Use Geocoding API (V3)
</release>
<release version="1.0" date="2012-05-12" min="2.3">
- Symphony 2.3 compatibility
- Show map of location in entry table and publish panel
Expand Down
25 changes: 12 additions & 13 deletions fields/field.geocoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,46 +230,45 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu
Compile:
-------------------------------------------------------------------------*/

private function __geocodeAddress($address) {

private function __geocodeAddress($address, $can_return_default=true) {
$coordinates = null;

$cache_id = md5('maplocationfield_' . $address);
$cache = new Cacheable(Symphony::Database());
$cachedData = $cache->check($cache_id);
$cachedData = $cache->check($cache_id);

// no data has been cached
if(!$cachedData) {

include_once(TOOLKIT . '/class.gateway.php');
include_once(TOOLKIT . '/class.gateway.php');

$ch = new Gateway;
$ch->init();
$ch->setopt('URL', 'http://maps.google.com/maps/geo?q='.urlencode($address).'&output=json');
$ch->setopt('URL', 'http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
$response = json_decode($ch->exec());

$coordinates = $response->Placemark[0]->Point->coordinates;
$coordinates = $response->results[0]->geometry->location;

if ($coordinates && is_array($coordinates)) {
$cache->write($cache_id, $coordinates[1] . ', ' . $coordinates[0], $this->_geocode_cache_expire); // cache lifetime in minutes
if ($coordinates && is_object($coordinates)) {
$cache->write($cache_id, $coordinates->lat . ', ' . $coordinates->lng, $this->_geocode_cache_expire); // cache lifetime in minutes
}

}
// fill data from the cache
else {
else {
$coordinates = $cachedData['data'];
}

// coordinates is an array, split and return
if ($coordinates && is_array($coordinates)) {
return $coordinates[1] . ', ' . $coordinates[0];
// coordinates is an object, split and return
if ($coordinates && is_object($coordinates)) {
return $coordinates->lat . ', ' . $coordinates->lng;
}
// return comma delimeted string
elseif ($coordinates) {
return $coordinates;
}
// return default coordinates
else {
elseif ($return_default) {
return '0, 0';
}
}
Expand Down

0 comments on commit 5a1eb1e

Please sign in to comment.