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

Add photon's bbox param #472

Merged
merged 2 commits into from Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion geopy/geocoders/photon.py
Expand Up @@ -82,7 +82,8 @@ def geocode(
location_bias=None,
language=False,
limit=None,
osm_tag=None
osm_tag=None,
bbox=None
):
"""
Return a location point by address.
Expand All @@ -109,6 +110,12 @@ def geocode(
filters are required as ``['key:!val', '!key', ':!value']``.
:type osm_tag: str or list or set

:param bbox: The bounding box of the viewport within which
to bias geocode results more prominently.
Example: ``[Point(22, 180), Point(-22, -180)]``.
:type bbox: list or tuple of 2 items of :class:`geopy.point.Point` or
``(latitude, longitude)`` or ``"%(latitude)s, %(longitude)s"``.

:rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
``exactly_one=False``.

Expand All @@ -130,6 +137,11 @@ def geocode(
except ValueError:
raise ValueError(("Location bias must be a"
" coordinate pair or Point"))

if bbox:
params['bbox'] = self._format_bounding_box(
bbox, "%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)s")

if osm_tag:
if isinstance(osm_tag, str):
params['osm_tag'] = [osm_tag]
Expand Down
6 changes: 6 additions & 0 deletions test/geocoders/photon.py
Expand Up @@ -35,6 +35,12 @@ async def test_osm_tag(self):
{"latitude": 44.3862491, "longitude": -88.290994, "delta": 2.0},
)

async def test_bbox(self):
await self.geocode_run(
{"query": "Marbach", "bbox": [(50.16, 10.67), (50.17, 10.68)]},
{"latitude": 50.1667628, "longitude": 10.6786321, "delta": 2.0},
)

async def test_unicode_name(self):
await self.geocode_run(
{"query": "\u6545\u5bab"},
Expand Down