function getGoogleMap() { if (!Config::get('googleMapEnabled') || empty($this->address) || empty($this->city) || empty($this->country)) { return false; } $googleMap = new GoogleMap(); $googleMap->setZoomLevel(15); $longAddress = $this->address . ', ' . $this->city . ', ' . $this->country; $map = $googleMap->getScriptCode(); try { try { if (!is_null($this->lat) && !is_null($this->lng)) { $googleMap->addGeoPoint($this->lat, $this->lng, $longAddress); } else { $point = $googleMap->addAddress($longAddress); if ($point !== false) { Model::factoryInstance('site')->updateByPk($point, $this->siteId); } } } catch (Google_Map_AddressNotFoundException $e) { try { // No valid points for google map then search by zipCode City $googleMap->addAddress($this->zipCode . ', ' . $this->city . ', ' . $this->country); } catch (Google_Map_AddressNotFound_Exception $e) { // No valid points for google map then search by country $googleMap->addAddress($this->country); $googleMap->setZoomLevel(12); } } $map .= $googleMap->getMapCode(); return $map; } catch (Google_Map_ServiceException $e) { // geolocalization is temporary disabled for this IP, try user mode $googleMap->setZoomLevel(Config::get('googleMapZoom')); $googleMap->setZoomLevel(15); $map .= $googleMap->getUserSideMapCode($this->address . ', ' . $this->city . ', ' . $this->country); return $map; } catch (Exception $e) { return ''; } }