* Modificado para implementar algunas mejoras como visualizar rutas,
* visualización de latitud y longitud en tiempo real,
* enlazar un punto concreto, elegir el tipo de mapa...
*
* Está todo explicado en
* http://sukiweb.net/archivos/2007/01/20/mapas-de-google-maps-sencillos/
*/
class PhoogleMap{
var $validPoints = array();
var $tracks = array();
// Distintos tipos G_MAP_TYPE,G_SATELLITE_TYPE,G_HYBRID_TYPE
var $MapType ="G_MAP_TYPE";
var $invalidPoints = array();
var $mapWidth = 720;
var $mapHeight = 500;
// Incluye aquí tu API KEY
var $apiKey = "";
var $showControl = true;
var $showType = true;
//* 'small' or 'large'
var $controlType = 'small';
// int: 0-17
var $zoomLevel = 6;
function addGeoPoint($lat,$long,$infoHTML){
$pointer = count($this->validPoints);
$this->validPoints[$pointer]['lat'] = $lat;
$this->validPoints[$pointer]['long'] = $long;
$this->validPoints[$pointer]['htmlMessage'] = $infoHTML;
}
function addTrack($color){
$pointer = count($this->tracks);
$this->tracks[$pointer]['color'] = $color;
}
function addPolyline($lat,$long){
$track = count($this->tracks)-1;
$pointer = count($this->polylines[$track]);
$this->polylines[$track][$pointer]['lat'] = $lat;
$this->polylines[$track][$pointer]['long'] = $long;
}
function centerMap($lat,$long){
$this->centerMap = "map.centerAndZoom(new GPoint(".$long.",".$lat."), ".$this->zoomLevel.");\n";
}
function addAddress($address,$htmlMessage=null){
if (!is_string($address)){
die("All Addresses must be passed as a string");
}
$apiURL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=";
$addressData = file_get_contents($apiURL.urlencode($address));
$results = $this->xml2array($addressData);
if (empty($results['ResultSet']['Result']['Address'])){
$pointer = count($this->invalidPoints);
$this->invalidPoints[$pointer]['lat']= $results['ResultSet']['Result']['Latitude'];
$this->invalidPoints[$pointer]['long']= $results['ResultSet']['Result']['Longitude'];
$this->invalidPoints[$pointer]['passedAddress'] = $address;
$this->invalidPoints[$pointer]['htmlMessage'] = $htmlMessage;
}else{
$pointer = count($this->validPoints);
$this->validPoints[$pointer]['lat']= $results['ResultSet']['Result']['Latitude'];
$this->validPoints[$pointer]['long']= $results['ResultSet']['Result']['Longitude'];
$this->validPoints[$pointer]['passedAddress'] = $address;
$this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;
}
}
function showValidPoints($displayType,$css_id){
$total = count($this->validPoints);
if ($displayType == "table"){
echo "
\n\n\tAddress | \n
\n";
for ($t=0; $t<$total; $t++){
echo"\n\t".$this->validPoints[$t]['passedAddress']." | \n
\n";
}
echo "
\n";
}
if ($displayType == "list"){
echo "\n";
for ($lst=0; $lst<$total; $lst++){
echo "- ".$this->validPoints[$lst]['passedAddress']."
\n";
}
echo "
\n";
}
}
function showInvalidPoints($displayType,$css_id){
$total = count($this->invalidPoints);
if ($displayType == "table"){
echo "\n\n\tAddress | \n
\n";
for ($t=0; $t<$total; $t++){
echo"\n\t".$this->invalidPoints[$t]['passedAddress']." | \n
\n";
}
echo "
\n";
}
if ($displayType == "list"){
echo "\n";
for ($lst=0; $lst<$total; $lst++){
echo "- ".$this->invalidPoints[$lst]['passedAddress']."
\n";
}
echo "
\n";
}
}
function setWidth($width){
$this->mapWidth = $width;
}
function setHeight($height){
$this->mapHeight = $height;
}
function setAPIkey($key){
$this->apiKey = $key;
}
function printGoogleJS(){
echo "\n\n";
}
function showMap(){
echo "\nmapWidth."px; height: ".$this->mapHeight."px\">\n
\n";
echo " \n";
echo "";
}
///////////THIS BLOCK OF CODE IS FROM Roger Veciana's CLASS (assoc_array2xml) OBTAINED FROM PHPCLASSES.ORG//////////////
function xml2array($xml){
$this->depth=-1;
$this->xml_parser = xml_parser_create();
xml_set_object($this->xml_parser, $this);
xml_parser_set_option ($this->xml_parser,XML_OPTION_CASE_FOLDING,0);//Don't put tags uppercase
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser,"characterData");
xml_parse($this->xml_parser,$xml,true);
xml_parser_free($this->xml_parser);
return $this->arrays[0];
}
function startElement($parser, $name, $attrs){
$this->keys[]=$name;
$this->node_flag=1;
$this->depth++;
}
function characterData($parser,$data){
$key=end($this->keys);
$this->arrays[$this->depth][$key]=$data;
$this->node_flag=0;
}
function endElement($parser, $name)
{
$key=array_pop($this->keys);
if($this->node_flag==1){
$this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];
unset($this->arrays[$this->depth+1]);
}
$this->node_flag=1;
$this->depth--;
}
//////////////////END CODE FROM Roger Veciana's CLASS (assoc_array2xml) /////////////////////////////////
}//End Of Class
?>