Skip to content

Conversation

@leewillis77
Copy link

The attached patch adds support for setting the bounds on GoogleMaps provider requests which allow you to set a preference for the results that are returned. See:

https://developers.google.com/maps/documentation/geocoding/intro#geocoding

@willdurand
Copy link
Member

This would break the "common provider API".. @geocoder-php/geocoder WDYT?

@vicchi
Copy link
Member

vicchi commented Oct 17, 2016

Almost all of the "conventional" street level geocoding services support constraining results via a bounding box. A quick dive through various provider's documentation shows this is supported by ArcGIS, Google, Mapzen, Nominatim, TomTom and Yandex.

So this isn't an unreasonable enhancement IMHO.

We're also coming up to thinking about what Geocoder 4.0 will look like and as we're hiking the major version number, this is a good time to think about expanding the current common provider API.

This will need some thought about how to represent this consistently through the various providers as well as how to handle cases where this isn't supported.

As a concept, I think this is a valid one, but not the way in which it's implemented in this PR though.

@stevevance
Copy link
Contributor

+1 to having the bounding box parameter. This can drastically improve search results.

@Nyholm Nyholm added this to the 4.0.0 milestone Oct 18, 2016
@Baachi
Copy link
Member

Baachi commented Oct 25, 2016

I'm not a big fan of it, as @willdurand said it will break the "common provider API". If you use this feature, you can't change the provider easily.

@Nyholm
Copy link
Member

Nyholm commented Oct 26, 2016

I agree with both @willdurand and @Baachi. This library is meant to give a "common provider API". That means that a third party library author should be able to write something like this and be confident that the code works no matter what geocoder is provided.

class ThirdPartyCode
  public function __construct(Geocoder $gecoder) {
    $this->geocoder = $geocoder;
  }
  public function bar() {
    $result = $this->geocoder->geocode('foobar');
    // ...
  }

The third party library does not care if you change the geocoder provider. This is called the Liskov substitution principle.


However. A application author should be able to make a decision that he/she never will change the provider. The application code may not type hint for Geocoder but for GoogleMaps or GeocoderThatSupportsBoundsInterface.

class ApplicationCode
  public function __construct(GoogleMaps $gecoder) {
    $this->geocoder = $geocoder;
  }
  public function bar() {
    $this->geocoder->setBounds(/* .. */);
    $result = $this->geocoder->geocode('foobar');
    // ...
  }

My point is that this library should define a contract which all geocoder providers MUST follow. But a specific provider (or a group of providers) may have some extra features. I see to issues with supporting that. I am 👍 for a PR like this.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this PR. But we need an interface for this feature. I suggest creating an interface named BoundsAwareProvider.

I also miss some tests and you need to rebase.

return $this;
}

public function setBounds($bounds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this parameter be type hinted with Bounds?

}

if (null !== $this->bounds) {
$query = sprintf('%s&bounds=%s', $query, $this->bounds);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated since $this->bounds should be a Bounds object.

@Nyholm
Copy link
Member

Nyholm commented Jan 3, 2017

I just created #576

@Nyholm Nyholm mentioned this pull request Feb 19, 2017
4 tasks
@Nyholm
Copy link
Member

Nyholm commented May 20, 2017

This is now supported with GeocodeQuery::setBounds

@Nyholm Nyholm closed this May 20, 2017
@Nyholm
Copy link
Member

Nyholm commented May 20, 2017

Sorry, it was only the Query that had bounds support. I added a PR to make sure you can use bounds with google. See #627

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants