Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Geocoder service provider for Laravel

License

NotificationsYou must be signed in to change notification settings

geocoder-php/GeocoderLaravel

 
 

Repository files navigation

Latest StableVersionTotal DownloadsBuild StatusCode Coverate Report

Geocoder for Laravel

If you still useLaravel 4, please check out the0.4.x branchhere.

Version 1.0.0 is a backwards-compatibility-breaking update. Please reviewthis documentation, especially theUsage section before installing.

This package allows you to useGeocoderinLaravel 5.

Installation

  1. Install the package via composer:
composer require toin0u/geocoder-laravel

Once 1.0.0 is stable, we will update this command to reflect that. In the interest of getting it out and into your hands, a temporary RC build is best.

  1. Find theproviders array key inconfig/app.php and register theGeocoder Service Provider:
// 'providers' => [Geocoder\Laravel\Providers\GeocoderService::class,// ];

Upgrading

If you are upgrading from a pre-1.x version of this package, please keep thefollowing things in mind:

  1. Update your composer.json file as follows:

    "toin0u/geocoder-laravel":"^1.0",
  2. Remove yourconfig/geocoder.php configuration file. (If you need to customize it, follow the configuration instructions below.)

  3. Remove any Geocoder alias in the aliases section of yourconfig/app.php. (This package auto-registers the aliases.)

  4. Update the service provider entry in yourconfig/app.php to read:

    Geocoder\Laravel\Providers\GeocoderService::class,
  5. If you are using the facade in your code, you have two options:

    1. Replace the facadesGeocoder:: (and remove the correspondinguse statements) withapp('geocoder')->.

    2. Update theuse statements to the following:

      useGeocoder\Laravel\Facades\Geocoder;
  6. Update your query statements to use->get() (to retrieve a collection ofGeoCoder objects) or->all() (to retrieve an array of arrays), then iterateto process each result.

Configuration

Pay special attention to the language and region values if you are using them.For example, the GoogleMaps provider uses TLDs for region values, and thefollowing for language values:https://developers.google.com/maps/faq#languagesupport.

Further, a special note on the GoogleMaps provider: if you are using an API key,you must also use set HTTPS to true. (Best is to leave it true always, unlessthere is a special requirement not to.)

See theGeocoder documentation for a listof available adapters and providers.

Default Settings

By default, the configuration specifies a Chain Provider as the first provider,containing GoogleMaps and FreeGeoIp providers. The first to return a resultwill be returned. After the Chain Provider, we have added the BingMaps providerfor use in specific situations (providers contained in the Chain provider willbe run by default, providers not in the Chain provider need to be calledexplicitly). The second GoogleMaps Provider outside of the Chain Provider isthere just to illustrate this point (and is used by the PHPUnit tests).

return ['providers' => [        Chain::class => [            GoogleMaps::class => ['en','us',true,env('GOOGLE_MAPS_API_KEY'),            ],            FreeGeoIp::class  => [],        ],        BingMaps::class => ['en-US',env('BING_MAPS_API_KEY'),        ],        GoogleMaps::class => ['en','us',true,env('GOOGLE_MAPS_API_KEY'),        ],    ],'adapter'  => CurlHttpAdapter::class,];

Customization

If you would like to make changes to the default configuration, publish andedit the configuration file:

php artisan vendor:publish --provider="Geocoder\Laravel\Providers\GeocoderService" --tag="config"

Usage

The service provider initializes thegeocoder service, accessible via thefacadeGeocoder::... or the application helperapp('geocoder')->....

Geocoding Addresses

Get Collection of Addresses

app('geocoder')->geocode('Los Angeles, CA')->get();

Get Array of Addresses

app('geocoder')->geocode('Los Angeles, CA')->all();

Reverse-Geocoding

app('geocoder')->reverse(43.882587,-103.454067)->get();

Dumping Results

app('geocoder')->geocode('Los Angeles, CA')->dump('kml');

Changelog

https://github.com/geocoder-php/GeocoderLaravel/blob/master/CHANGELOG.md

Support

If you are experiencing difficulties, please please open an issue on GitHub:https://github.com/geocoder-php/GeocoderLaravel/issues.

Contributor Code of Conduct

Please note that this project is released with aContributor Code of Conduct.By participating in this project you agree to abide by its terms.

License

GeocoderLaravel is released under the MIT License. See the bundledLICENSEfile for details.


[8]ページ先頭

©2009-2025 Movatter.jp