public function getHeader()
	{
		if (!$this->getOption('key'))
		{
			throw new UnexpectedValueException('A Google Maps API key is required.');
		}

		$zoom = $this->getZoom();
		$center = $this->getCenter();
		$maptype = $this->getMapType();
		$id = $this->getMapID();
		$scheme = $this->isSecure() ? 'https' : 'http';
		$key = $this->getKey();
		$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 .= substr(json_encode($this->getAdditionalMapOptions()), 1, -1);
		$setup .= '};';
		$setup .= "var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);";

		foreach ($this->listMarkers() as $marker)
		{
			$loc = $marker['loc'];
			$title = $marker['title'];
			$options = $marker['options'];

			$setup .= 'new google.maps.Marker({';
			$setup .= "position: new google.maps.LatLng({$loc[0]},{$loc[1]}),";
			$setup .= 'map: map,';
			$setup .= "title:'{$title}',";
			$setup .= substr(json_encode($options), 1, -1);
			$setup .= '});';
		}

		$setup .= $this->getAdditionalJavascript();

		if ($this->isAsync())
		{
			$asynccallback = $this->getAsyncCallback();

			$output = '<script type="text/javascript">';
			$output .= "function {$asynccallback}() {";
			$output .= $setup;
			$output .= '}';

			$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);';
			$onload .= '}';
		}
		else
		{
			$output = "<script type='text/javascript' src='{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}'>";
			$output .= '</script>';
			$output .= '<script type="text/javascript">';

			$onload = "function() {";
			$onload .= $setup;
			$onload .= '}';
		}

		switch ($this->getAutoload())
		{
			case 'onload':
				$output .= "window.onload={$onload};";
				break;

			case 'jquery':
				$output .= "$(document).ready({$onload});";
				break;

			case 'mootools':
				$output .= "window.addEvent('domready',{$onload});";
				break;
		}

		$output .= '</script>';

		return $output;
	}
public function getHeader()
	{
		if (!$this->getOption('key'))
		{
			throw new UnexpectedValueException('A Google Maps API key is required.');
		}

		$zoom = $this->getZoom();
		$center = $this->getCenter();
		$maptype = $this->getMapType();
		$id = $this->getMapID();
		$scheme = $this->isSecure() ? 'https' : 'http';
		$key = $this->getKey();
		$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 .= substr(json_encode($this->getAdditionalMapOptions()), 1, -1);
		$setup .= '};';
		$setup .= "var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);";

		foreach ($this->listMarkers() as $marker)
		{
			$loc = $marker['loc'];
			$title = $marker['title'];
			$options = $marker['options'];

			$setup .= 'new google.maps.Marker({';
			$setup .= "position: new google.maps.LatLng({$loc[0]},{$loc[1]}),";
			$setup .= 'map: map,';
			$setup .= "title:'{$title}',";
			$setup .= substr(json_encode($options), 1, -1);
			$setup .= '});';
		}

		$setup .= $this->getAdditionalJavascript();

		if ($this->isAsync())
		{
			$asynccallback = $this->getAsyncCallback();

			$output = '<script type="text/javascript">';
			$output .= "function {$asynccallback}() {";
			$output .= $setup;
			$output .= '}';

			$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);';
			$onload .= '}';
		}
		else
		{
			$output = "<script type='text/javascript' src='{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}'>";
			$output .= '</script>';
			$output .= '<script type="text/javascript">';

			$onload = "function() {";
			$onload .= $setup;
			$onload .= '}';
		}

		switch ($this->getAutoload())
		{
			case 'onload':
				$output .= "window.onload={$onload};";
				break;

			case 'jquery':
				$output .= "$(document).ready({$onload});";
				break;

			case 'mootools':
				$output .= "window.addEvent('domready',{$onload});";
				break;
		}

		$output .= '</script>';

		return $output;
	}
public function getHeader ( ) { if ( ! $ this -> getOption ( 'key' ) ) { throw new UnexpectedValueException ( 'A Google Maps API key is required.' ) ; } $ zoom = $ this -> getZoom ( ) ; $ center = $ this -> getCenter ( ) ; $ maptype = $ this -> getMapType ( ) ; $ id = $ this -> getMapID ( ) ; $ scheme = $ this -> isSecure ( ) ? 'https' : 'http' ; $ key = $ this -> getKey ( ) ; $ 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 .= substr ( json_encode ( $ this -> getAdditionalMapOptions ( ) ) , 1 , - 1 ) ; $ setup .= '};' ; $ setup .= "var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);" ; foreach ( $ this -> listMarkers ( ) as $ marker ) { $ loc = $ marker [ 'loc' ] ; $ title = $ marker [ 'title' ] ; $ options = $ marker [ 'options' ] ; $ setup .= 'new google.maps.Marker({' ; $ setup .= "position: new google.maps.LatLng({$loc[0]},{$loc[1]})," ; $ setup .= 'map: map,' ; $ setup .= "title:'{$title}'," ; $ setup .= substr ( json_encode ( $ options ) , 1 , - 1 ) ; $ setup .= '});' ; } $ setup .= $ this -> getAdditionalJavascript ( ) ; if ( $ this -> isAsync ( ) ) { $ asynccallback = $ this -> getAsyncCallback ( ) ; $ output = '<script type="text/javascript">' ; $ output .= "function {$asynccallback}() {" ; $ output .= $ setup ; $ output .= '}' ; $ 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);' ; $ onload .= '}' ; } else { $ output = "<script type='text/javascript' src='{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}'>" ; $ output .= '</script>' ; $ output .= '<script type="text/javascript">' ; $ onload = "function() {" ; $ onload .= $ setup ; $ onload .= '}' ; } switch ( $ this -> getAutoload ( ) ) { case 'onload' : $ output .= "window.onload={$onload};" ; break ; case 'jquery' : $ output .= "$(document).ready({$onload});" ; break ; case 'mootools' : $ output .= "window.addEvent('domready',{$onload});" ; break ; } $ output .= '</script>' ; return $ output ; }
Get code to load Google Maps javascript

@return  string  Javascript code

@since   1.0
@throws  UnexpectedValueException
Get code to load Google Maps javascript