Source for file maps.php
Documentation is available at maps.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE
* Google Maps embed class for the Joomla Platform.
* @package Joomla.Platform
* @var JHttp The HTTP client object to use in sending HTTP requests.
* @param JRegistry $options Google options object
* @param JUri $uri URL of the page being rendered
* @param JHttp $http Http client for geocoding requests
public function __construct(JRegistry $options =
null, JUri $uri =
null, JHttp $http =
null)
* Method to get the API key
* @return string The Google Maps API key
* Method to set the API key
* @param string $key The Google Maps API key
* @return JGoogleEmbedMaps The object for method chaining
* Method to get the id of the map div
* Method to set the map div id
* @param string $id The ID
* @return JGoogleEmbedMaps The object for method chaining
* Method to get the class of the map div
* @return string The class
* Method to set the map div class
* @param string $class The class
* @return JGoogleEmbedMaps The object for method chaining
* Method to get the style of the map div
* @return string The style
* Method to set the map div style
* @param string $style The style
* @return JGoogleEmbedMaps The object for method chaining
* Method to get the map type setting
* @return string The class
* Method to set the map type ()
* @param string $type Valid types are ROADMAP, SATELLITE, HYBRID, and TERRAIN
* @return JGoogleEmbedMaps The object for method chaining
* Method to get additional map options
* @return string The options
* Method to add additional map options
* @param array $options Additional map options
* @return JGoogleEmbedMaps The object for method chaining
* Method to get additional map options
* @return string The options
* Method to add additional javascript
* @param array $script Additional javascript
* @return JGoogleEmbedMaps The object for method chaining
* @return int The zoom level
* Method to set the map zoom
* @param int $zoom Zoom level (0 is whole world)
* @return JGoogleEmbedMaps The object for method chaining
* Method to set the center of the map
* @return mixed A latitude longitude array or an address string
* Method to set the center of the map
* @param mixed $location A latitude/longitude array or an address string
* @param mixed $title Title of marker or false for no marker
* @param array $markeroptions Options for marker
* @return JGoogleEmbedMaps The latitude/longitude of the center or false on failure
public function setCenter($location, $title =
true, $markeroptions =
array())
if (!$marker =
$this->addMarker($location, $title, $markeroptions))
$location =
$marker['loc'];
$location =
$geocode['geometry']['location'];
* Add a marker to the map
* @param mixed $location A latitude longitude array or an address string
* @param mixed $title The hover-text for the marker
* @param array $options Options for marker
* @return mixed The marker or false on failure
public function addMarker($location, $title =
null, $options =
array())
$location =
$geocode['geometry']['location'];
$marker =
array('loc' =>
$location, 'title' =>
$title, 'options' =>
$options);
* List the markers added to the map
* @return array A list of markers
* Delete a marker from the map
* @param int $index Index of marker to delete (defaults to last added marker)
* @return array The latitude/longitude of the deleted marker
$index =
count($markers) -
1;
if ($index >=
count($markers) ||
$index <
0)
throw
new OutOfBoundsException('Marker index out of bounds.');
$marker =
$markers[$index];
* Checks if the javascript is set to be asynchronous
* @return boolean True if asynchronous
* Load javascript asynchronously
* @return JGoogleEmbedMaps The object for method chaining
* Load javascript synchronously
* @return JGoogleEmbedAMaps The object for method chaining
* Method to get callback function for async javascript loading
* Method to set the callback function for async javascript loading
* @param string $callback The callback function name
* @return JGoogleEmbedMaps The object for method chaining
* Checks if a sensor is set to be required
* @return boolean True if asynchronous
* Require access to sensor data
* @return JGoogleEmbedMaps The object for method chaining
* Don't require access to sensor data
* @return JGoogleEmbedAMaps The object for method chaining
* Checks how the script should be loaded
* @return string Autoload type (onload, jquery, mootools, or false)
* Automatically add the callback to the window
* @param string $type The method to add the callback (options are onload, jquery, mootools, and false)
* @return JGoogleEmbedAMaps The object for method chaining
* Get code to load Google Maps javascript
* @return string Javascript code
throw
new UnexpectedValueException('A Google Maps API key is required.');
$scheme =
$this->isSecure() ?
'https' :
'http';
$sensor =
$this->hasSensor() ?
'true' :
'false';
$setup =
'var mapOptions = {';
$setup .=
"zoom: {$zoom},";
$setup .=
"center: new google.maps.LatLng({$center[0]},{$center[1]}),";
$setup .=
"mapTypeId: google.maps.MapTypeId.{$maptype},";
$setup .=
"var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);";
$title =
$marker['title'];
$options =
$marker['options'];
$setup .=
'new google.maps.Marker({';
$setup .=
"position: new google.maps.LatLng({$loc[0]},{$loc[1]}),";
$setup .=
"title:'{$title}',";
$output =
'<script type="text/javascript">';
$output .=
"function {$asynccallback}() {";
$onload =
"function() {";
$onload .=
'var script = document.createElement("script");';
$onload .=
'script.type = "text/javascript";';
$onload .=
"script.src = '{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}&callback={$asynccallback}';";
$onload .=
'document.body.appendChild(script);';
$output =
"<script type='text/javascript' src='{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}'>";
$output .=
'<script type="text/javascript">';
$onload =
"function() {";
$output .=
"window.onload={$onload};";
$output .=
"$(document).ready({$onload});";
$output .=
"window.addEvent('domready',{$onload});";
* Method to retrieve the div that the map is loaded into
* @return string The body
$output =
"<div id='{$id}'";
$output .=
" class='{$class}'";
$output .=
" style='{$style}'";
* Method to get the location information back from an address
* @param string $address The address to geocode
* @return array An array containing Google's geocode data
$url =
'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' .
urlencode($address);
$response =
$this->http->get($url);
if ($response->code <
200 ||
$response->code >=
300)
throw
new RuntimeException('Error code ' .
$response->code .
' received geocoding address: ' .
$response->body .
'.');
throw
new RuntimeException('Invalid json received geocoding address: ' .
$response->body .
'.');
if ($data['status'] !=
'OK')
return $data['results'][0];
Documentation generated on Tue, 19 Nov 2013 15:07:38 +0100 by phpDocumentor 1.4.3