quexer69/php-google-api

Google 地图 API 调用、Staticmap、Geocode 的集合

3.2.0 2014-10-08 17:08 UTC

This package is auto-updated.

Last update: 2024-09-14 07:42:43 UTC


README

Latest Stable Version Total Downloads License

...适用于 Google Map API v3, PHP >= 5.3.0, Yii 1.*

###配置

在你的应用和/或控制台配置文件中,添加以下内容

'components' => array(
	'googleMapApi'   => array(
			'class'             => 'vendor.quexer69.php-google-api.GoogleMapApi',
            /**
             * Google Maps Image and Geocode API settings
             */
            'staticmap_api_key' => '***************************************',
            'geocode_api_key'   => '***************************************',
            'map_type'          => 'terrain',
            'map_size'          => '520x350',
            'map_sensor'        => false,
            'map_zoom'          => 9,
            'map_scale'         => 1,
            'map_image_path'    => '/images/google_map',
            'map_marker_color'  => 'red',
            'map_iframe_width'  => '100%',
            'map_iframe_height' => '500', // in px
            'language'          => 'de',
            'quiet'             => false
	),
	...
),

###使用方法

只需输入地址字符串,就像你在谷歌地图上操作一样!

$address 	          = '70180 Stuttgart, Germany';
$filePath             = Yii::app()->googleMapApi->createImage($address,null);

按经纬度查询

$latlng 	          = '48.7632145,9.174027';
$filePath             = Yii::app()->googleMapApi->createImage(null, $latlng);

计算两个地理点之间的距离

$latlng_origin	      = array('48.7632145,9.174027');
$latlng_destination	  = array('48.4525334,9.468254');
$unit		          = 'miles' // or 'km'

$distance		      = Yii::app()->googleMapApi->getDistance($latlng_origin, $latlng_destination, $unit);

###公共方法

public function getGoogleMapIframe($address, $latlng, $iFrameWidth, $iFrameHeight)

public function createImage($address, $latlng, $setMarker)

public function getGeoCodeObject($address, $latlng)

public function getDistance($start, $finish, $unit)

public static function getCountryByCode($short_country_code)