1
- # Google Maps Geocoder provider
1
+ # Google Places Geocoder provider
2
2
[ ![ 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 )
3
3
[ ![ 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 )
4
4
[ ![ Total Downloads] ( https://poser.pugx.org/geocoder-php/google-maps-places-provider/downloads )] ( https://packagist.org/packages/geocoder-php/google-maps-places-provider )
7
7
[ ![ 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 )
8
8
[ ![ Software License] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square )] ( LICENSE )
9
9
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.
12
12
13
13
## Install
14
-
15
14
``` bash
16
15
composer require geocoder-php/google-maps-places-provider
17
16
```
@@ -20,34 +19,87 @@ composer require geocoder-php/google-maps-places-provider
20
19
https://developers.google.com/places/web-service
21
20
22
21
## 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.
24
23
25
24
### Geocoding
26
25
This provider supports two different modes of geocoding by text.
27
26
28
27
#### Find Mode
29
28
This is the default mode. It required an exact places name. It's not very forgiving, and generally only returns a single result
30
29
30
+ ``` php
31
+ $results = $provider->geocodeQuery(
32
+ GeocodeQuery::create('Museum of Contemporary Art Australia')
33
+ );
34
+ ```
35
+
31
36
#### 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.
33
38
It's a lot more forgiving that the ` find ` mode, but results will contain all fields and thus be billed at the highest rate.
34
39
35
40
``` 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
+ ```
37
46
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
+ );
40
55
```
41
56
42
57
### 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
+ ```
45
92
46
93
``` 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
+ );
48
100
```
49
101
50
102
### Contribute
51
103
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
53
105
report any issues you find on the [ issue tracker] ( https://github.com/geocoder-php/Geocoder/issues ) .
0 commit comments