diff --git a/app.py b/app.py index a3b8907..82a063b 100644 --- a/app.py +++ b/app.py @@ -60,13 +60,34 @@ def search(): params = { "q": query, "format": "jsonv2", - "limit": 8, + "limit": 20, "addressdetails": 1, "extratags": 1, "namedetails": 1, "dedupe": 1, } + # Restrict results to the area currently visible on the map. + # Expected format: "left,top,right,bottom" (lon,lat pairs). + viewbox = request.args.get("viewbox", "").strip() + + if viewbox: + parts = [p.strip() for p in viewbox.split(",")] + + if len(parts) == 4: + try: + left, top, right, bottom = ( + float(p) for p in parts + ) + + params["viewbox"] = "{},{},{},{}".format( + left, top, right, bottom + ) + params["bounded"] = 1 + + except ValueError: + pass + try: results = nominatim_request( NOMINATIM_SEARCH_URL, diff --git a/templates/index.html b/templates/index.html index 8dfae32..0859676 100644 --- a/templates/index.html +++ b/templates/index.html @@ -699,51 +699,72 @@