Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different geocoders #47

Closed
hohl opened this issue Sep 9, 2016 · 5 comments
Closed

Use different geocoders #47

hohl opened this issue Sep 9, 2016 · 5 comments

Comments

@hohl
Copy link

hohl commented Sep 9, 2016

Sometimes I want to geocode IP addresses of my users and sometimes I want to geocode addresses. For the IP addresses I would like to use the FreeGeoIpProvider, for the addresses I would like to use the GoogleMapsProvider. Is there any way to switch between the configured providers in code?

I've seen there is a method called using in the Geocode facade. However, I couldn't get it working.

@hohl
Copy link
Author

hohl commented Sep 11, 2016

How should the use statement help me with my problem, xitude? I want to use the Facade provided by this plugin with different providers. If I would use the providers directly I wouldn't need that plugin at all because then I could have used the Geocoder package directly. (Which may not even a bad idea, since this plugin seems a bit outdated too, since it still does rely on Geocoder 2 when there is Geocoder 3 out already for a while).

@mikebronner
Copy link
Member

mikebronner commented Sep 11, 2016

@hohl, that's exactly what I did yesterday. Upgraded to the php version of geocoder, and it ended up being even easier to use than this one. While I appreciate the work done on this package, it being out of date is actually starting to cause problems (which were aleviated as soon as I implemented the current php package).

Here is the trait I use on my models that need it (sure, can use some refactoring, but it shows how easy it is to implement).

<?php namespace App\Traits;

use Geocoder\Provider\GoogleMaps;
use Ivory\HttpAdapter\CurlHttpAdapter;
use Illuminate\Support\Collection;

trait Geocodable
{
    public function geocode(string $address) : Collection
    {
        $adapter = new CurlHttpAdapter();
        $geocoder = new GoogleMaps($adapter);

        return collect($geocoder->geocode($address)->all());
    }
}

@mikebronner mikebronner self-assigned this Sep 30, 2016
@mikebronner mikebronner added this to the 0.7 milestone Sep 30, 2016
@mikebronner
Copy link
Member

mikebronner commented Sep 30, 2016

Working on new release ... will add example to documentation on making this work with the chain provider.

@mikebronner
Copy link
Member

Having researched this some more, this will require a separate PR. However, I would like to implement it, as I think its increadibly useful. I will submit a PR to the parent repo, and if that is rejected, implement it locally for the laravel repo (however, that might cause some oddities as we would have diverging functionality, something we should avoid). If anyone wants to help out with this, please submit a PR to the main geocoder repo and reference this issue, if I don't get to it first, or if one hasn't already been created.

@mikebronner
Copy link
Member

Figured out a better solution requiring no additional PR. Will be in next release. Please keep an eye on this and re-open if it happens again after release. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants