|
1 |
| -Geocoder for Lavarel 5 |
2 |
| -====================== |
3 |
| - |
4 |
| -If you still use **Laravel 4**, please check out the `0.4.x` branch [here](https://github.com/geocoder-php/GeocoderLaravel/tree/0.4.x). |
5 |
| - |
6 |
| -This package allows you to use [**Geocoder**](http://geocoder-php.org/Geocoder/) |
7 |
| -in [**Laravel 5**](http://laravel.com/). |
8 |
| - |
9 | 1 | [](https://packagist.org/packages/toin0u/geocoder-laravel)
|
| 2 | +use Toin0u\Geocoder\GeocoderServiceProvider; |
10 | 3 | [](https://packagist.org/packages/toin0u/geocoder-laravel)
|
11 | 4 | [](http://travis-ci.org/geocoder-php/GeocoderLaravel)
|
12 | 5 | [](https://coveralls.io/r/geocoder-php/GeocoderLaravel)
|
13 | 6 |
|
| 7 | +# Geocoder for Lavarel |
14 | 8 |
|
15 |
| -Installation |
16 |
| ------------- |
17 |
| - |
18 |
| -It can be found on [Packagist](https://packagist.org/packages/toin0u/geocoder-laravel). |
19 |
| -The recommended way is through [composer](http://getcomposer.org). |
20 |
| - |
21 |
| -Edit `composer.json` and add: |
| 9 | +> If you still use **Laravel 4**, please check out the `0.4.x` branch |
| 10 | + [here](https://github.com/geocoder-php/GeocoderLaravel/tree/0.4.x). |
22 | 11 |
|
23 |
| -```json |
24 |
| -{ |
25 |
| - "require": { |
26 |
| - "toin0u/geocoder-laravel": "@stable" |
27 |
| - } |
28 |
| -} |
29 |
| -``` |
| 12 | +** Version 0.7.0 is a backwards-compatibility-breaking update. Please review |
| 13 | + this documentation, especially the _Usage_ section before installing. ** |
30 | 14 |
|
31 |
| -**Protip:** you should browse the |
32 |
| -[`toin0u/geocoder-laravel`](https://packagist.org/packages/toin0u/geocoder-laravel) |
33 |
| -page to choose a stable version to use, avoid the `@stable` meta constraint. |
| 15 | +This package allows you to use [**Geocoder**](http://geocoder-php.org/Geocoder/) |
| 16 | + in [**Laravel 5**](http://laravel.com/). |
| 17 | + |
| 18 | +## Installation |
| 19 | +1. Install the package via composer: |
| 20 | + ```sh |
| 21 | + composer require toin0u/geocoder-laravel |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Find the `providers` array key in `config/app.php` and register the **Geocoder |
| 25 | + Service Provider**: |
| 26 | + ```php |
| 27 | + // 'providers' => [ |
| 28 | + Toin0u\GeocoderLaravel\Providers\GeocoderService::class, |
| 29 | + // ]; |
| 30 | + ``` |
34 | 31 |
|
35 |
| -And install dependencies: |
36 |
| -```bash |
37 |
| -$ composer update |
| 32 | +## Configuration |
| 33 | +Pay special attention to the language and region values if you are using them. |
| 34 | + For example, the GoogleMaps provider uses TLDs for region values, and the |
| 35 | + following for language values: https://developers.google.com/maps/faq#languagesupport. |
| 36 | + |
| 37 | +Further, a special note on the GoogleMaps provider: if you are using an API key, |
| 38 | + you must also use set HTTPS to true. (Best is to leave it true always, unless |
| 39 | + there is a special requirement not to.) |
| 40 | + |
| 41 | +See the [Geocoder documentation](http://geocoder-php.org/Geocoder/) for a list |
| 42 | + of available adapters and providers. |
| 43 | + |
| 44 | +### Default Settings |
| 45 | +By default, the configuration specifies a Chain Provider as the first provider, |
| 46 | + containing GoogleMaps and FreeGeoIp providers. The first to return a result |
| 47 | + will be returned. After the Chain Provider, we have added the BingMaps provider |
| 48 | + for use in specific situations (providers contained in the Chain provider will |
| 49 | + be run by default, providers not in the Chain provider need to be called |
| 50 | + explicitly). The second GoogleMaps Provider outside of the Chain Provider is |
| 51 | + there just to illustrate this point (and is used by the PHPUnit tests). |
| 52 | +```php |
| 53 | +return [ |
| 54 | + 'providers' => [ |
| 55 | + Chain::class => [ |
| 56 | + GoogleMaps::class => [ |
| 57 | + 'en', |
| 58 | + 'us', |
| 59 | + true, |
| 60 | + env('GOOGLE_MAPS_API_KEY'), |
| 61 | + ], |
| 62 | + FreeGeoIp::class => [], |
| 63 | + ], |
| 64 | + BingMaps::class => [ |
| 65 | + 'en-US', |
| 66 | + env('BING_MAPS_API_KEY'), |
| 67 | + ], |
| 68 | + GoogleMaps::class => [ |
| 69 | + 'en', |
| 70 | + 'us', |
| 71 | + true, |
| 72 | + env('GOOGLE_MAPS_API_KEY'), |
| 73 | + ], |
| 74 | + ], |
| 75 | + 'adapter' => CurlHttpAdapter::class, |
| 76 | +]; |
38 | 77 | ```
|
39 | 78 |
|
40 |
| -If you do not have [**Composer**](https://getcomposer.org) installed, run these two commands: |
41 |
| - |
42 |
| -```bash |
43 |
| -$ curl -sS https://getcomposer.org/installer | php |
44 |
| -$ php composer.phar install |
| 79 | +### Customization |
| 80 | +If you would like to make changes to the default configuration, publish and |
| 81 | + edit the configuration file: |
| 82 | +```sh |
| 83 | +php artisan vendor:publish --provider="Toin0u\Geocoder\GeocoderServiceProvider" --tags="config" |
45 | 84 | ```
|
46 | 85 |
|
| 86 | +## Usage |
| 87 | +The service provider initializes the `geocoder` service, accessible via the |
| 88 | + facade `Geocoder::...` or the application helper `app('geocoder')->...`. |
47 | 89 |
|
48 |
| -Usage |
49 |
| ------ |
50 |
| - |
51 |
| -Find the `providers` array key in `config/app.php` and register the **Geocoder Service Provider**. |
52 |
| - |
| 90 | +### Geocoding Addresses |
| 91 | +#### Get Collection of Addresses |
53 | 92 | ```php
|
54 |
| -'providers' => array( |
55 |
| - // ... |
56 |
| - |
57 |
| - Toin0u\Geocoder\GeocoderServiceProvider::class, |
58 |
| -) |
| 93 | +app('geocoder')->geocode('Los Angeles, CA')->get(); |
59 | 94 | ```
|
60 | 95 |
|
61 |
| -Find the `aliases` array key in `config/app.php` and register the **Geocoder Facade**. |
62 |
| - |
| 96 | +#### Get Array of Addresses |
63 | 97 | ```php
|
64 |
| -'aliases' => array( |
65 |
| - // ... |
66 |
| - |
67 |
| - 'Geocoder' => Toin0u\Geocoder\Facade\Geocoder::class, |
68 |
| -) |
| 98 | +app('geocoder')->geocode('Los Angeles, CA')->all(); |
69 | 99 | ```
|
70 | 100 |
|
71 |
| -## Configuration |
72 |
| -Publish and edit the configuration file |
73 |
| - |
74 |
| -```sh |
75 |
| -php artisan vendor:publish --provider="Toin0u\Geocoder\GeocoderServiceProvider" --tags="config" |
76 |
| -``` |
77 |
| - |
78 |
| -The service provider creates the following services: |
79 |
| - |
80 |
| -* `geocoder`: the Geocoder instance. |
81 |
| -* `geocoder.chain`: the chain provider used by Geocoder. |
82 |
| -* `geocoder.adapter`: the HTTP adapter used to get data from remotes APIs. |
83 |
| - |
84 |
| -By default, the `geocoder.chain` service contains `GoogleMapsProvider` and `FreeGeoIpProvider`. |
85 |
| -The `geocoder.adapter` service uses the cURL adapter. Override these services to use the |
86 |
| -adapter/providers you want by editing `config/geocoder.php`: |
87 |
| - |
| 101 | +#### Reverse-Geocoding |
88 | 102 | ```php
|
89 |
| -return [ |
90 |
| - 'providers' => [ |
91 |
| - '\Geocoder\Provider\GoogleMapsProvider' => ['en_EN', 'my-region', $ssl = false, 'MY_API_KEY'], |
92 |
| - '\Geocoder\Provider\GoogleMapsBusinessProvider' => ['my-locale', 'my-region', $ssl = true, 'MY_API_KEY'], |
93 |
| - ], |
94 |
| - 'adapter' => '\Geocoder\HttpAdapter\CurlHttpAdapter' |
95 |
| -]; |
| 103 | +app('geocoder')->reverse('Los Angeles, CA')->all(); |
96 | 104 | ```
|
97 | 105 |
|
98 |
| -NB: As you can see the array value of the provider is the constructor arguments. |
99 |
| - |
100 |
| -See [the Geocoder documentation](http://geocoder-php.org/Geocoder/) for a list of available adapters and providers. |
101 |
| - |
102 |
| - |
103 |
| -Example with Facade |
104 |
| -------------------- |
105 |
| - |
| 106 | +#### Dumping Results |
106 | 107 | ```php
|
107 |
| -<?php |
108 |
| - |
109 |
| -// ... |
110 |
| -try { |
111 |
| - $geocode = Geocoder::geocode('10 rue Gambetta, Paris, France'); |
112 |
| - // The GoogleMapsProvider will return a result |
113 |
| - var_dump($geocode); |
114 |
| -} catch (\Exception $e) { |
115 |
| - // No exception will be thrown here |
116 |
| - echo $e->getMessage(); |
117 |
| -} |
| 108 | +app('geocoder')->reverse('Los Angeles, CA')->dump('kml'); |
118 | 109 | ```
|
119 | 110 |
|
| 111 | +## Changelog |
| 112 | +https://github.com/geocoder-php/GeocoderLaravel/blob/master/CHANGELOG.md |
120 | 113 |
|
121 |
| -Changelog |
122 |
| ---------- |
123 |
| - |
124 |
| -[See the CHANGELOG file](https://github.com/geocoder-php/GeocoderLaravel/blob/master/CHANGELOG.md) |
125 |
| - |
126 |
| - |
127 |
| -Support |
128 |
| -------- |
129 |
| - |
130 |
| -[Please open an issue on GitHub](https://github.com/geocoder-php/GeocoderLaravel/issues) |
131 |
| - |
132 |
| - |
133 |
| -Contributor Code of Conduct |
134 |
| ---------------------------- |
135 |
| - |
136 |
| -Please note that this project is released with a Contributor Code of Conduct. |
137 |
| -By participating in this project you agree to abide by its terms. |
138 |
| - |
| 114 | +## Support |
| 115 | +If you are experiencing difficulties, please please open an issue on GitHub: |
| 116 | + https://github.com/geocoder-php/GeocoderLaravel/issues. |
139 | 117 |
|
140 |
| -License |
141 |
| -------- |
| 118 | +## Contributor Code of Conduct |
| 119 | +Please note that this project is released with a |
| 120 | + [Contributor Code of Conduct](https://github.com/geocoder-php/Geocoder#contributor-code-of-conduct). |
| 121 | + By participating in this project you agree to abide by its terms. |
142 | 122 |
|
| 123 | +## License |
143 | 124 | GeocoderLaravel is released under the MIT License. See the bundled
|
144 |
| -[LICENSE](https://github.com/geocoder-php/GeocoderLaravel/blob/master/LICENSE) |
145 |
| -file for details. |
| 125 | + [LICENSE](https://github.com/geocoder-php/GeocoderLaravel/blob/master/LICENSE) |
| 126 | + file for details. |
0 commit comments