在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):alexpechkarev/google-maps开源软件地址(OpenSource Url):https://github.com/alexpechkarev/google-maps开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Collection of Google Maps API Web Services for LaravelProvides convenient way of setting up and making requests to Maps API from Laravel application. For services documentation, API key and Usage Limits visit Google Maps API Web Services and Maps API for Terms of Service License Restrictions. Features
DependencyNotesRmoving Place Add, Delete & Radar Search features Requests to the Places API attempting to use these features will receive an error response
Deprication notices for Google Places API Web Service that effects Premium data (Zagat), types parameter, id and reference fields.
InstallationIssue following command in console: For laravel 6 use composer require alexpechkarev/google-maps Alternatively edit composer.json by adding following line and run "require": {
....,
"alexpechkarev/google-maps":"^8.0",
}, ConfigurationRegister package service provider and facade in 'config/app.php' 'providers' => [
...
GoogleMaps\ServiceProvider\GoogleMapsServiceProvider::class,
]
'aliases' => [
...
'GoogleMaps' => GoogleMaps\Facade\GoogleMapsFacade::class,
] Publish configuration file using Open configuration file /*
|----------------------------------
| Service Keys
|------------------------------------
*/
'key' => 'ADD YOUR SERVICE KEY HERE', If you like to use different keys for any of the services, you can overwrite master API Key by specifying it in the UsageHere is an example of making request to Geocoding API: $response = \GoogleMaps::load('geocoding')
->setParam (['address' =>'santa cruz'])
->get(); By default, where appropriate, Required parameters can be specified as an array of $response = \GoogleMaps::load('geocoding')
->setParam ([
'address' =>'santa cruz',
'components' => [
'administrative_area' => 'TX',
'country' => 'US',
]
])
->get(); Alternatively parameters can be set using $endpoint = \GoogleMaps::load('geocoding')
->setParamByKey('address', 'santa cruz')
->setParamByKey('components.administrative_area', 'TX') //return $this
... Another example showing request to Places API Place Add service: $response = \GoogleMaps::load('placeadd')
->setParam([
'location' => [
'lat' => -33.8669710,
'lng' => 151.1958750
],
'accuracy' => 0,
"name" => "Google Shoes!",
"address" => "48 Pirrama Road, Pyrmont, NSW 2009, Australia",
"types" => ["shoe_store"],
"website" => "http://www.google.com.au/",
"language" => "en-AU",
"phone_number" => "(02) 9374 4000"
])
->get(); Available methods
Accepts string as parameter, web service name as specified in configuration file. Returns reference to it's self. \GoogleMaps::load('geocoding')
...
Accepts string as parameter, $response = \GoogleMaps::load('geocoding')
->setEndpoint('json') // return $this
...
Returns string. $endpoint = \GoogleMaps::load('geocoding')
->setEndpoint('json')
->getEndpoint();
echo $endpoint; // output 'json'
Accepts two parameters:
Deeply nested array can use 'dot' notation to assign value. Returns reference to it's self. $endpoint = \GoogleMaps::load('geocoding')
->setParamByKey('address', 'santa cruz')
->setParamByKey('components.administrative_area', 'TX') //return $this
...
Accepts array of parameters Returns reference to it's self. $response = \GoogleMaps::load('geocoding')
->setParam([
'address' => 'santa cruz',
'components' => [
'administrative_area' => 'TX',
'country' => 'US',
]
]) // return $this
...
Returns web service response in the format specified by $response = \GoogleMaps::load('geocoding')
->setParamByKey('address', 'santa cruz')
->setParamByKey('components.administrative_area', 'TX')
->get();
var_dump( json_decode( $response ) ); // output
/*
{\n
"results" : [\n
{\n
"address_components" : [\n
{\n
"long_name" : "277",\n
"short_name" : "277",\n
"types" : [ "street_number" ]\n
},\n
...
*/
Example with $response = \GoogleMaps::load('geocoding')
->setParamByKey('latlng', '40.714224,-73.961452')
->get('results.formatted_address');
var_dump( json_decode( $response ) ); // output
/*
array:1 [▼
"results" => array:9 [▼
0 => array:1 [▼
"formatted_address" => "277 Bedford Ave, Brooklyn, NY 11211, USA"
]
1 => array:1 [▼
"formatted_address" => "Grand St/Bedford Av, Brooklyn, NY 11211, USA"
]
...
*/
This method only available with Google Maps Directions API. Accepted parameter:
$response = \GoogleMaps::load('directions')
->setParam([
'origin' => 'place_id:ChIJ685WIFYViEgRHlHvBbiD5nE',
'destination' => 'place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y',
])
->isLocationOnEdge(55.86483,-4.25161);
dd( $response ); // true
This method only available with Google Maps Directions API. Accepted parameter:
$response = \GoogleMaps::load('directions')
->setParam([
'origin' => 'place_id:ChIJ685WIFYViEgRHlHvBbiD5nE',
'destination' => 'place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y',
])
->containsLocation(55.86483,-4.25161);
dd( $response ); // true SupportPlease open an issue on GitHub LicenseCollection of Google Maps API Web Services for Laravel is released under the MIT License. See the bundled LICENSE file for details. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论