Phpgoogleapi interface project_php tutorial

Source: Internet
Author: User
Phpgoogleapi interface program. Phpgoogleapi interface program is a fully funtional class generated Google map. Multiple types of customization are allowed, allowing users to quickly implement a php google api interface within a few minutes.

Php google api interface program

Here is a full funtional class that generates Google Maps. Multiple types of customization are allowed, allowing users to quickly implement the knowledge of Google map APIs without any website JavaScript or Google maps within minutes.

Class phproogleMap {

/*
* @ The google api key
*/
Private $ apiKey;

/*
* @ The map zoom level
*/
Private $ mapZoom = 8;

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

/*
* @ The height of the map p
*/
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 p
*/
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 'mapzoo ':
If (filter_var ($ value, FILTER_VALIDATE_INT, array ("options" => array ("min_range" => 0, "max_range" => 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" => 100, "max_range" => 900) = false)
{
Throw new Exception ("$ name is out of range ");
}
$ This-> $ name = $ value;
Break;

Case 'mapheight ':
If (filter_var ($ value, FILTER_VALIDATE_INT, array ("options" => array ("min_range" => 100, "max_range" => 900) = false)
{
Throw new Exception ("$ name is out of range ");
}
$ 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 'mapzoo ':
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 are here, throw an example ton ***/
Throw new Exception ("$ name is invalid ");
}


/*
*
* @ Isset
*
* @ Access public
*
*/
Public function _ isset ($ name)
{
Switch ($ name)
{
Case 'apikey ':
$ This-> apiKey = $ name;
Break;

Case 'mapzoo ':
$ 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 longpolling
*
* @ 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'

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.