Example #1
0
 /**
  * Returns HTML text to access GoogleMap.
  * @param address - address string to generate map for.
  * @param zoom.
  */
 public static function getGoogleMap($address, $zoom, $iframe)
 {
     $key = self::getApiKey();
     $encoded = urlencode($address);
     $coder = new GeoCoder($encoded, $key);
     $code = $coder->invoke();
     $mapRep = "";
     if ($iframe != null && $iframe == "true") {
         $mapRep .= "    <div id='map' style='width: 500px; height: 300px'></div>\n" . self::getMapScript($address, $zoom, $code->getLatitude(), $code->getLongitude(), $key) . "    <script type='text/javascript'>\n" . "       loadScript();\n" . "    </script>\n";
     } else {
         $mapRep .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'\n" . "  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n" . "<html xmlns='http://www.w3.org/1999/xhtml'>\n" . "  <head>\n" . "    <meta http-equiv='content-type' content='text/html; charset=utf-8'/>\n" . "    <title>Google Maps JavaScript API Example</title>\n" . self::getMapScript($address, $zoom, $code->getLatitude(), $code->getLongitude(), $key) . "  </head>\n" . "  <body onload='loadScript()' onunload='GUnload()'>\n" . "    <div id='map' style='width: 500px; height: 300px'></div>\n" . "  </body>\n" . "</html>";
     }
     $result = new RestResponse();
     $result->setResponseBody($mapRep);
     return $result;
 }
 /**
  * Get the geocode result object from the geocoder object.
  * @param string $apiKey           - google map api key.
  * @param array  $geoCodeQueryData - required query data in the form of array.
  * @return object                  - geocoder result object.
  */
 public static function getGeoCodeResultByData($apiKey, $geoCodeQueryData)
 {
     assert('$apiKey == null || is_string($apiKey)');
     assert('is_array($geoCodeQueryData)');
     Yii::import('application.extensions.geocoder.*');
     $geoCoder = new GeoCoder();
     $geoCoder->setApiKey($apiKey);
     $geoCoder->setApiDriver('Google');
     $geoCoder->init();
     $geoCodeDriver = GeoCode_Driver::factory($geoCoder->getApiDriver(), $apiKey);
     if ($geoCodeQueryData['latitude'] == null && $geoCodeQueryData['longitude'] == null) {
         $geoCodeResult = $geoCoder->query($geoCodeQueryData['query']);
         $geoCodeQueryData['latitude'] = $geoCodeResult->latitude;
         $geoCodeQueryData['longitude'] = $geoCodeResult->longitude;
         return new GeoCode_Result($geoCodeDriver, $geoCodeQueryData);
     } else {
         return new GeoCode_Result($geoCodeDriver, $geoCodeQueryData);
     }
 }