phpgoogleapi接口程序_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了phpgoogleapi接口程序_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含9226字,纯文字阅读大概需要14分钟。
内容图文
![phpgoogleapi接口程序_PHP教程](/upload/InfoBanner/zyjiaocheng/173/a941f11026d741d5bcfce660d55a0b47.jpg)
php google api 接口程序
这里是一个完全funtional类生成谷歌地图。 允许多类定制,使用户能够快速实现在几分钟之内就没有任何网站的JavaScript或谷歌地图谷歌地图API的知识。
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" => 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 for" );
}
$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 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 are 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 '' ;
}
public function drawMap ()
{
$js = ' mapDivID . '" style="width: ' . $this -> mapWidth . 'px; height: ' . $this -> mapHeight . '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 ***/
$map -> addMarker (- 33.858362 , 151.214876 , '
Sydney Opera House
For those with culture
' );$map -> addMarker (- 33.862828 , 151.216974 , '
Royal Botanic GardensA 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 (); ?>
常用的google地图开发参数
phproogle::apiKey
.这是谷歌的用户API密钥。 .这也可以设置使用时,一个新的实例是instanciated构造。
phproogle::addGoogleMapControl() phproogle::addGoogleMapControl()
此方法设置,如缩放控制控制器的谷歌地图,地图控制等此方法可以多次调用设置地图多个控件。 Options are:选项有:
* 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:这将设置地图类型的四个选项之一:
* normal正常
* satellite卫星
* hybrid混合
* physical物理
mapType = "normal" ; ?>
phproogle::mapCenter phproogle::mapCenter
T这将设置分区范围内的地图中心。 该值是一个包含的纬度和经度的地图中心的顺序。
$map->mapCenter = array(-33.862828, 151.216974); 1 $map->mapCenter = array(-33.862828, 151.216974); 1
phproogle::mapZoom phproogle::mapZoom
这将设置地图缩放级别。 零值是最广泛的缩放级别,并显示整个世界。 虽然19日是最高变焦,将显示建筑物。 Each zoom level doubles the zoom.每个缩放级别的两倍变焦。 12.默认值为12。
phproogle::addMarker() phproogle::addMarker()
This function is used to create and place markers upon the map.这个函数用于创建和地点后,地图标记。 the addMarker method takes three args.在addMarker argS的方法有三个。
* float $latitude浮动$纬度
* float $longitude浮动$经度
* string $html字符串$的HTML
.经度和纬度都是数字值和HTML可以是任何HTML或文本将在标记球囊内。
phproogle::addMarkerAddress() phproogle::addMarkerAddress()
此方法类似于phproogle::addMarker()和地方在地图上的标记。 然而,而不是接受经度和纬度来放置标志,这种方法需要两个值。
* string $address字符串$地址
* string $html字符串$的HTML
参数的地址,如“二街宫人至法国巴黎简单的地址”。 balloon.在HTML参数再次,任何文本或HTML放置在信息气球。
phproogle::mapDivID phproogle::mapDivID
当设置,这将设置组ID的映射居住于默认值是“地图”
phproogle::mapWidth phproogle::mapWidth
顾名思义,这将设置div的宽度该地图居住于默认宽度为350像素。
phproogle::mapHeight phproogle::mapHeight
这将设置分区的高度该地图居住于默认值是300像素。
phproogle::googleJS() phproogle::googleJS()
此方法返回的JavaScript字符串,用于在文件头,显示与谷歌API密钥连接字符串最频繁。
phproogle::drawMap() phproogle::drawMap()
此方法返回的JavaScript制作完成的地图本身。
http://www.bkjia.com/PHPjc/444981.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444981.htmlTechArticlephp google api 接口程序 php google api 接口程序 这里是一个完全funtional类生成谷歌地图。 允许多类定制,使用户能够快速实现在几分钟之内就没...
内容总结
以上是互联网集市为您收集整理的phpgoogleapi接口程序_PHP教程全部内容,希望文章能够帮你解决phpgoogleapi接口程序_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。