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