Skip to content

Commit

Permalink
Add photon's bbox param (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed Mar 20, 2021
1 parent aa28d4c commit 43501f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion geopy/geocoders/photon.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 43501f6

Please sign in to comment.