PHP Google API interface Program _php Tutorial

Source: Internet
Author: User
PHP Google API Interface program

PHP Google API Interface program

Here is a complete funtional class generated by Google Maps. Allows multi-class customization, enabling users to quickly realize the knowledge of Google Maps API without any Web site within a few minutes of JavaScript or Google Maps.

Class Phprooglemap {

/*
* @The Google API key
*/
Private $apiKey;

/*
* @the Map Zoom level
*/
Private $mapZoom = 8;

/*
* @The width of the map div
*/
Private $mapWidth = 350;

/*
* @The height of the map div
*/
Private $mapHeight = 300;

/*
* @The Map Center
*/
Private $mapCenter;

/*
* The array of map types
*/
Private $googleMapTypes;

/*
* @The Map type
*/
Private $mapType = ' normal ';

/*
* @The array of marker points
*/
Private $markerPoints = Array ();

/*
* @The array of marker addresses
*/
Private $markerAddresses = Array ();

/*
* @The Maps Controls
*/
Private $googleMapControls = Array ();

/*
* @The ID of the map div
*/
Private $mapDivID;

/*
* The constructor
*
* @param ApiKey
*
* @access Public
*
* @return void
*
*/
Public function __construct ($apiKey = null)
{
$this-ApiKey = Is_null ($apiKey)? ": $apiKey;
/*** set the map types ***/
$this-Setgooglemaptypes ();
}


/*
*
* @setter
*
* @access Public
*
*/
Public Function __set ($name, $value)
{
Switch ($name)
{
Case ' ApiKey ':
if (! is_string ($value))
{
throw new Exception ($name, $value, ' string ');
}
$this $name = $value;
Break

Case ' Mapzoom ':
if (Filter_var ($value, Filter_validate_int, Array ("options" = = Array ("Min_range" = 0, "Max_range" and "= 19") )) = = False)
{
throw new Exception ("$name is out of range");
}
$this $name = $value;
Break

Case ' mapwidth ':
if (Filter_var ($value, Filter_validate_int, Array ("options" = = Array ("Min_range" and "max_range" = 90 0))) = = False)
{
throw new Exception ("$name is out of range for");
}
$this $name = $value;
Break

Case ' mapheight ':
if (Filter_var ($value, Filter_validate_int, Array ("options" = = Array ("Min_range" and "max_range" = 90 0))) = = False)
{
throw new Exception ("$name is out of range for");
}
$this $name = $value;
Break

Case ' Maptype ':
if (! array_key_exists ($value, $this-googlemaptypes))
{
throw new Exception ("$name is not a valid map type");
}
$this $name = $value;
Break

Case ' Mapdivid ':
if (! is_string ($value))
{
throw new Exception ("$name is not a valid ID");
}
$this $name = $value;
Break

Case ' Mapcenter ':
if (! Is_array ($value))
{
throw new Exception ("$name is not a valid array");
}
$this $name = $value;
Break

Default
throw new Exception ("Invalid Parameter $name");
}
}


/*
*
* @getter
*
* @access Public
*
*/
Public Function __get ($name)
{
Switch ($name)
{
Case ' ApiKey ':
return $this, ApiKey;
Break

Case ' Mapzoom ':
return $this, Mapzoom;
Break

Case ' mapwidth ':
return $this, Mapwidth;
Break

Case ' mapheight ':
return $this, Mapheight;
Break

Case ' Maptype ':
return $this, Maptype;
Break

Case ' Mapdivid ':
return $this, Mapdivid;
Break

Case ' Mapcenter ';
return $this, Mapcenter;
Break
}
/*** If we is here, throw an Excepton ***/
throw new Exception ("$name is invalid");
}


/*
*
* @isset
*
* @access Public
*
*/
Public Function __isset ($name)
{
Switch ($name)
{
Case ' ApiKey ':
$this-ApiKey = $name;
Break

Case ' Mapzoom ':
$this-mapzoom = $name;
Break

Case ' mapwidth ':
$this-mapwidth = $name;
Break

Case ' mapheight ':
$this-mapheight = $name;
Break

Case ' Maptype ':
$this-maptype = $name;
Break

Case ' Mapdivid ':
$this-mapdivid = $name;
Break

Case ' Mapcenter ';
$this-mapcenter = $name;
Break

Default
return false;
}
}


/*
*
* @Set the map types
*
* @access Private
*
* @return void
*
*/
Private Function Setgooglemaptypes ()
{
$this-googlemaptypes = Array (' physical ' = ' g_physical_map ', ' normal ' = ' g_normal_map ', ' satellite ' = ' G_satellite_map ', ' hybrid ' = ' g_hybrid_map ');
}

/*
*
* @add to the array of Google Maps controls
*
* @access Public
*
* @return void
*
*/
Public Function Addgooglemapcontrol ($control)
{
$n = sizeof ($this-googlemapcontrols);
$this-Googlemapcontrols [] = $control;
}
/*
*
* @get pinpoint marker by address
*
* @access Public
*
* @param string $address
*
* @param string $html
*
* @return void
*
*/
Public Function addmarkeraddress ($address, $html)
{
$s = sizeof ($this-markeraddresses);
$this-markeraddresses [$s] [address] = $address;
$this-markeraddresses [$s] [' html '] = $html;
}

/*
*
* @get pinpoint mark by latitude or longitude
*
* @access Public
*
* @param string $lat
*
* @param string $long
*
* @param string $html
*
* @return void
*
*/
Public Function Addmarker ($lat, $long, $html)
{
$pointer = sizeof ($this-markerpoints);
$this-Markerpoints [$pointer] [lat] = $lat;
$this-Markerpoints [$pointer] [' long '] = $long;
$this-Markerpoints [$pointer] [' html '] = $html;
}


/*
*
* @The JavaScript for Google to connect
*
* @access Public
*
* @return String
*
*/
Public Function Googlejs ()
{
Return '. "N";
}

Private Function Nojavascript ()
{
Return ' JavaScript must is enabled in the order for-use Google Maps.
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
Try again.
' ;
}


Public Function Drawmap ()
{
$js = ' Mapdivid. ' "style=" width: '. Mapwidth, $this. ' px; Height: '. Mapheight, $this. ' px ' > ';
$js. = $this-Nojavascript ();

$js. = '
' ;

return $JS;

}

}/*** end of class ***/


Try
{
/*** A new Phproogle instance ***/
$map = new Phprooglemap ();

/*** the Google API key ***/
$map-ApiKey = ' your_google_api_key ';

/*** Zoom is 0-19 ***/
$map-mapzoom = 14;

/*** the map width ***/
$map-mapwidth = 350;

/*** the map height ***/
$map-mapheight = 300;

/*** set the map type ***/
$map-Maptype = ' normal ';

/*** Set the map center ***/
$map-Mapcenter = Array (-33.862828, 151.216974);

/*** add some markers with latitude and longitude ***/
Addmarker, $map (-33.858362, 151.214876, '

Sydney Opera House

For those with culture

' );
Addmarker, $map (-33.862828, 151.216974, '

Royal Botanic Gardens

A link here ');


/*** Add some controls ***/
$map-Addgooglemapcontrol (' Gmaptypecontrol ');
$map-Addgooglemapcontrol (' Gsmallmapcontrol ');
$map-Addgooglemapcontrol (' Goverviewmapcontrol ');

/*** add some marker addresses ***/
$map-Addmarkeraddress (' 2 Pitt St Sydney NSW Australia ', '

Head Office

' );
$map-addmarkeraddress (' 122 Pitt St Sydney NSW Australia ', '

The Factory

' );

/*** set the map div ID ***/
$map-mapdivid = ' map ';
}
catch (Exception $e)
{
Echo $e-getMessage ();
}
?>



Googlejs ();?>


Drawmap ();?>

Common Google Maps Development parameters

Phproogle::apikey
This is Google's user API key: This can also be set when using a new instance of the instanciated construct.
Phproogle::addgooglemapcontrol () Phproogle::addgooglemapcontrol ()
This method settings, such as zoom control Controller for Google Maps, map control, etc. this method can be called multiple times to set the map for several controls. Options are: The option is:

* Glargemapcontrol Glargemapcontrol
* Gsmallmapcontrol Gsmallmapcontrol
* Gsmallzoomcontrol Gsmallzoomcontrol
* Gscalecontrol Gscalecontrol
* Gmaptypecontrol Gmaptypecontrol
* Ghierarchicalmaptypecontrol Ghierarchicalmaptypecontrol
* Goverviewmapcontrol Goverviewmapcontrol

Addgooglemapcontrol ("Gsmallmapcontrol");?>
Phproogle::maptype Phproogle::maptype
This sets, the map type to one of four options: This sets the four option for map types:

* Normal
* Satellite satellite
* Hybrid Mix
* Physical Physics

Maptype = "normal";?>
Phproogle::mapcenter Phproogle::mapcenter
T this sets the center of the map in the range of the partition. The value is a sequence that contains the latitude and longitude of the center of the map.
$map->mapcenter = Array (-33.862828, 151.216974); 1 $map->mapcenter = Array (-33.862828, 151.216974); 1
Phproogle::mapzoom Phproogle::mapzoom
This sets the map zoom level. The 0 value is the broadest zoom level and displays the entire world. Although 19th is the highest zoom, the building will be displayed. Each zoom level doubles the zoom at twice times the zoom levels. 12. The default value is 12.
Phproogle::addmarker () Phproogle::addmarker ()
This function was used to create and place markers upon the map. The functions are used for creating and location maps after the marker. The Addmarker method takes three args. There are three methods in Addmarker args.

* Float $latitude Float $ latitude
* Float $longitude Float $ longitude
* String $html The HTML of the $

. Longitude and latitude are both numeric values and HTML can be any HTML or text that will be inside the marker balloon.
Phproogle::addmarkeraddress () phproogle::addmarkeraddress ()
This method is similar to Phproogle::addmarker () and local markers on the map. However, instead of accepting longitude and latitude to place a flag, this method requires two values.

* String $address $ address
* String $html The HTML of the $

The address of the parameter, such as "Two Street Gongren to Paris, France simple address". Balloon. In the HTML parameter again, any text or HTML is placed in the information balloon.
Phproogle::mapdivid Phproogle::mapdivid
When set, this sets the mapping of the group ID to live at the default value of "map"
Phproogle::mapwidth Phproogle::mapwidth
As the name implies, this will set the width of the div that the map resides in by default width of 350 pixels.
Phproogle::mapheight Phproogle::mapheight
This sets the height of the partition to which the map resides at the default value of 300 pixels.
Phproogle::googlejs () Phproogle::googlejs ()
This method returns the JavaScript string that is used in the file header to display the most frequent connection string with the Google API key.
Phproogle::d rawmap () Phproogle::drawmap ()
This method returns the JavaScript produced by the completed map itself.


http://www.bkjia.com/PHPjc/444981.html www.bkjia.com true http://www.bkjia.com/PHPjc/444981.html techarticle PHP Google API interface program PHP Google API interface program here is a completely funtional class to generate Google Maps. Allows multi-class customization, so that users can quickly realize in a few minutes without ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.