1- # Google Maps Geocoder provider
1+ # Google Places Geocoder provider
22[ ![ Build Status] ( https://travis-ci.org/geocoder-php/google-maps-places-provider.svg?branch=master )] ( http://travis-ci.org/geocoder-php/google-maps-places-provider )
33[ ![ Latest Stable Version] ( https://poser.pugx.org/geocoder-php/google-maps-places-provider/v/stable )] ( https://packagist.org/packages/geocoder-php/google-maps-places-provider )
44[ ![ Total Downloads] ( https://poser.pugx.org/geocoder-php/google-maps-places-provider/downloads )] ( https://packagist.org/packages/geocoder-php/google-maps-places-provider )
77[ ![ Quality Score] ( https://img.shields.io/scrutinizer/g/geocoder-php/google-maps-places-provider.svg?style=flat-square )] ( https://scrutinizer-ci.com/g/geocoder-php/google-maps-places-provider )
88[ ![ Software License] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square )] ( LICENSE )
99
10- This is the Google Maps Places provider from the PHP Geocoder. This is a ** READ ONLY** repository. See the
11- [ main repo] ( https://github.com/geocoder-php/Geocoder ) for information and documentation.
10+ This is the Google Places provider from the PHP Geocoder. This is a ** READ ONLY** repository. See the
11+ [ main repo] ( https://github.com/geocoder-php/Geocoder ) for information and documentation.
1212
1313## Install
14-
1514``` bash
1615composer require geocoder-php/google-maps-places-provider
1716```
@@ -20,34 +19,87 @@ composer require geocoder-php/google-maps-places-provider
2019https://developers.google.com/places/web-service
2120
2221## Usage
23- This provider often requires extra data when making queries, due to requirements of the underlying places API.
22+ This provider often requires extra data when making queries, due to requirements of the underlying Places API.
2423
2524### Geocoding
2625This provider supports two different modes of geocoding by text.
2726
2827#### Find Mode
2928This is the default mode. It required an exact places name. It's not very forgiving, and generally only returns a single result
3029
30+ ``` php
31+ $results = $provider->geocodeQuery(
32+ GeocodeQuery::create('Museum of Contemporary Art Australia')
33+ );
34+ ```
35+
3136#### Search Mode
32- This mode will perform a search based on the input text.
37+ This mode will perform a search based on the input text.
3338It's a lot more forgiving that the ` find ` mode, but results will contain all fields and thus be billed at the highest rate.
3439
3540``` php
36- $findResults = $provider->geocodeQuery(GeocodeQuery::create('Museum of Contemporary Art Australia')); // One Result
41+ $results = $provider->geocodeQuery(
42+ GeocodeQuery::create('art museum sydney')
43+ ->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_SEARCH)
44+ );
45+ ```
3746
38- $searchResults = $provider->geocodeQuery(GeocodeQuery::create('art museum sydney'))
39- ->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_SEARCH); // 20 Results
47+ around location (which is similar to reverse geocoding, see below):
48+
49+ ``` php
50+ $results = $provider->geocodeQuery(
51+ GeocodeQuery::create('bar')
52+ ->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_SEARCH)
53+ ->withData('location', '-32.926642, 151.783026')
54+ );
4055```
4156
4257### Reverse Geocoding
43- When reverse geocoding, you are required to supply either a ` keyword ` , ` type ` or ` name ` .
44- See https://developers.google.com/places/web-service/search#PlaceSearchRequests
58+ Three options available for reverse geocoding of latlon coordinates:
59+
60+ - mode ` search ` + type (e.g.) ` bar ` : uses Google Place API [ Text search] ( https://developers.google.com/places/web-service/search#TextSearchRequests ) , requires ` type `
61+ - is similar to: Search around location (see previous section)
62+ - mode ` nearby ` + rankby ` distance ` : uses Google Place API [ Nearby search] ( https://developers.google.com/places/web-service/search#PlaceSearchRequests ) , requires ` type/keyword/name `
63+ - mode ` nearby ` + rankby ` prominence ` : uses Google Place API [ Nearby search] ( https://developers.google.com/places/web-service/search#PlaceSearchRequests ) , requires ` radius `
64+
65+ Default mode: ` search ` (because of backward compatibility). When using mode ` nearby ` default rankby: ` prominence ` .
66+ Mode ` search ` + type and mode ` nearby ` + type/keyword/name are very similar.
67+ Mode ` search ` gives formatted_address, mode ` nearby ` gives vicinity instead. E.g.:
68+
69+ - ` search ` : has "formatted_address": "7 Cope St, Redfern NSW 2016"
70+ - ` nearby ` : has "vicinity" instead: "7 Cope St, Redfern"
71+
72+ Examples
73+
74+ ``` php
75+ $results = $provider->reverseQuery(
76+ ReverseQuery::fromCoordinates(-33.892674, 151.200727)
77+ // ->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_SEARCH) // =default
78+ ->withData('type', 'bar') // requires type
79+ );
80+ $address = $results->first()->getFormattedAddress();
81+ ```
82+
83+ ``` php
84+ $results = $provider->reverseQuery(
85+ ReverseQuery::fromCoordinates(-33.892674, 151.200727)
86+ ->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_NEARBY)
87+ //->withData('rankby','prominence'); // =default
88+ ->withData('radius', 500) // requires radius (meters)
89+ );
90+ $vicinity = $results->first()->getVicinity();
91+ ```
4592
4693``` php
47- $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(-33.892674, 151.200727)->withData('type', 'bar'));
94+ $results = $provider->reverseQuery(
95+ ReverseQuery::fromCoordinates(-33.892674, 151.200727)
96+ ->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_NEARBY)
97+ ->withData('rankby','distance');
98+ ->withData('keyword', 'bar') // requires type/keyword/name
99+ );
48100```
49101
50102### Contribute
51103
52- Contributions are very welcome! Send a pull request to the [ main repository] ( https://github.com/geocoder-php/Geocoder ) or
104+ Contributions are very welcome! Send a pull request to the [ main repository] ( https://github.com/geocoder-php/Geocoder ) or
53105report any issues you find on the [ issue tracker] ( https://github.com/geocoder-php/Geocoder/issues ) .
0 commit comments