* @package GoogleMapAPI
* @version 2.5
*/
/* $Id: GoogleMapAPI.class.php,v 1.63 2007/08/03 16:29:40 mohrt Exp $ */
/*
For best results with GoogleMaps, use XHTML compliant web pages with this header:
For database caching, you will want to use this schema:
CREATE TABLE GEOCODES (
address varchar(255) NOT NULL default '',
lon float default NULL,
lat float default NULL,
PRIMARY KEY (address)
);
*/
class GoogleMapAPI {
/**
* PEAR::DB DSN for geocode caching. example:
* $dsn = 'mysql://user:pass@localhost/dbname';
*
* @var string
*/
var $dsn = null;
/**
* YOUR GooglMap API KEY for your site.
* (http://maps.google.com/apis/maps/signup.html)
*
* @var string
*/
var $api_key = '';
/**
* current map id, set when you instantiate
* the GoogleMapAPI object.
*
* @var string
*/
var $map_id = null;
/**
* sidebar
used along with this map.
*
* @var string
*/
var $sidebar_id = null;
/**
* GoogleMapAPI uses the Yahoo geocode lookup API.
* This is the application ID for YOUR application.
* This is set upon instantiating the GoogleMapAPI object.
* (http://developer.yahoo.net/faq/index.html#appid)
*
* @var string
*/
var $app_id = null;
/**
* use onLoad() to load the map javascript.
* if enabled, be sure to include on your webpage:
*
*
* @var string
*/
var $onload = true;
/**
* map center latitude (horizontal)
* calculated automatically as markers
* are added to the map.
*
* @var float
*/
var $center_lat = null;
/**
* map center longitude (vertical)
* calculated automatically as markers
* are added to the map.
*
* @var float
*/
var $center_lon = null;
/**
* enables map controls (zoom/move/center)
*
* @var boolean
*/
var $map_controls = true;
/**
* determines the map control type
* small -> show move/center controls
* large -> show move/center/zoom controls
*
* @var string
*/
var $control_size = 'large';
/**
* enables map type controls (map/satellite/hybrid)
*
* @var boolean
*/
var $type_controls = true;
/**
* default map type (G_NORMAL_MAP/G_SATELLITE_MAP/G_HYBRID_MAP)
*
* @var boolean
*/
var $map_type = 'G_NORMAL_MAP';
/**
* enables scale map control
*
* @var boolean
*/
var $scale_control = true;
/**
* enables overview map control
*
* @var boolean
*/
var $overview_control = false;
/**
* determines the default zoom level
*
* @var integer
*/
var $zoom = 16;
/**
* determines the map width
*
* @var integer
*/
var $width = '500px';
/**
* determines the map height
*
* @var integer
*/
var $height = '500px';
/**
* message that pops up when the browser is incompatible with Google Maps.
* set to empty string to disable.
*
* @var integer
*/
var $browser_alert = 'Sorry, the Google Maps API is not compatible with this browser.';
/**
* message that appears when javascript is disabled.
* set to empty string to disable.
*
* @var string
*/
var $js_alert = 'Javascript must be enabled in order to use Google Maps.';
/**
* determines if sidebar is enabled
*
* @var boolean
*/
var $sidebar = true;
/**
* determines if to/from directions are included inside info window
*
* @var boolean
*/
var $directions = true;
/**
* determines if map markers bring up an info window
*
* @var boolean
*/
var $info_window = true;
/**
* determines if info window appears with a click or mouseover
*
* @var string click/mouseover
*/
var $window_trigger = 'click';
/**
* what server geocode lookups come from
*
* available: YAHOO Yahoo! API. US geocode lookups only.
* GOOGLE Google Maps. This can do international lookups,
* but not an official API service so no guarantees.
* Note: GOOGLE is the default lookup service, please read
* the Yahoo! terms of service before using their API.
*
* @var string service name
*/
var $lookup_service = 'GOOGLE';
var $lookup_server = array('GOOGLE' => 'maps.google.com', 'YAHOO' => 'api.local.yahoo.com');
var $driving_dir_text = array(
'dir_to' => 'Start address: (include addr, city st/region)',
'to_button_value' => 'Get Directions',
'to_button_type' => 'submit',
'dir_from' => 'End address: (include addr, city st/region)',
'from_button_value' => 'Get Directions',
'from_button_type' => 'submit',
'dir_text' => 'Directions: ',
'dir_tohere' => 'To here',
'dir_fromhere' => 'From here'
);
/**
* version number
*
* @var string
*/
var $_version = '2.5';
/**
* list of added markers
*
* @var array
*/
var $_markers = array();
/**
* maximum longitude of all markers
*
* @var float
*/
var $_max_lon = -1000000;
/**
* minimum longitude of all markers
*
* @var float
*/
var $_min_lon = 1000000;
/**
* max latitude
*
* @var float
*/
var $_max_lat = -1000000;
/**
* min latitude
*
* @var float
*/
var $_min_lat = 1000000;
/**
* determines if we should zoom to minimum level (above this->zoom value) that will encompass all markers
*
* @var boolean
*/
var $zoom_encompass = true;
/**
* factor by which to fudge the boundaries so that when we zoom encompass, the markers aren't too close to the edge
*
* @var float
*/
var $bounds_fudge = 0.01;
/**
* use the first suggestion by a google lookup if exact match not found
*
* @var float
*/
var $use_suggest = false;
/**
* list of added polylines
*
* @var array
*/
var $_polylines = array();
/**
* icon info array
*
* @var array
*/
var $_icons = array();
/**
* database cache table name
*
* @var string
*/
var $_db_cache_table = 'GEOCODES';
/**
* class constructor
*
* @param string $map_id the id for this map
* @param string $app_id YOUR Yahoo App ID
*/
function GoogleMapAPI($map_id = 'map', $app_id = 'MyMapApp') {
$this->map_id = $map_id;
$this->sidebar_id = 'sidebar_' . $map_id;
$this->app_id = $app_id;
}
/**
* sets the PEAR::DB dsn
*
* @param string $dsn
*/
function setDSN($dsn) {
$this->dsn = $dsn;
}
/**
* sets YOUR Google Map API key
*
* @param string $key
*/
function setAPIKey($key) {
$this->api_key = $key;
}
/**
* sets the width of the map
*
* @param string $width
*/
function setWidth($width) {
if(!preg_match('!^(\d+)(.*)$!',$width,$_match))
return false;
$_width = $_match[1];
$_type = $_match[2];
if($_type == '%')
$this->width = $_width . '%';
else
$this->width = $_width . 'px';
return true;
}
/**
* sets the height of the map
*
* @param string $height
*/
function setHeight($height) {
if(!preg_match('!^(\d+)(.*)$!',$height,$_match))
return false;
$_height = $_match[1];
$_type = $_match[2];
if($_type == '%')
$this->height = $_height . '%';
else
$this->height = $_height . 'px';
return true;
}
/**
* sets the default map zoom level
*
* @param string $level
*/
function setZoomLevel($level) {
$this->zoom = (int) $level;
}
/**
* enables the map controls (zoom/move)
*
*/
function enableMapControls() {
$this->map_controls = true;
}
/**
* disables the map controls (zoom/move)
*
*/
function disableMapControls() {
$this->map_controls = false;
}
/**
* sets the map control size (large/small)
*
* @param string $size
*/
function setControlSize($size) {
if(in_array($size,array('large','small')))
$this->control_size = $size;
}
/**
* enables the type controls (map/satellite/hybrid)
*
*/
function enableTypeControls() {
$this->type_controls = true;
}
/**
* disables the type controls (map/satellite/hybrid)
*
*/
function disableTypeControls() {
$this->type_controls = false;
}
/**
* set default map type (map/satellite/hybrid)
*
*/
function setMapType($type) {
switch($type) {
case 'hybrid':
$this->map_type = 'G_HYBRID_MAP';
break;
case 'satellite':
$this->map_type = 'G_SATELLITE_MAP';
break;
case 'map':
default:
$this->map_type = 'G_NORMAL_MAP';
break;
}
}
/**
* enables onload
*
*/
function enableOnLoad() {
$this->onload = true;
}
/**
* disables onload
*
*/
function disableOnLoad() {
$this->onload = false;
}
/**
* enables sidebar
*
*/
function enableSidebar() {
$this->sidebar = true;
}
/**
* disables sidebar
*
*/
function disableSidebar() {
$this->sidebar = false;
}
/**
* enables map directions inside info window
*
*/
function enableDirections() {
$this->directions = true;
}
/**
* disables map directions inside info window
*
*/
function disableDirections() {
$this->directions = false;
}
/**
* set browser alert message for incompatible browsers
*
* @params $message string
*/
function setBrowserAlert($message) {
$this->browser_alert = $message;
}
/**
* set