3

How can I get list of possible result in Nominatim?

My code is

geolocator = Nominatim(user_agent="[email protected]")
location = geolocator.geocode("School")
location.raw

but unfortunately it only shows one result

geolocator = Nominatim(user_agent="[email protected]")

location = geolocator.geocode("School")

location.raw

{'place_id': 174509566,
 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
 'osm_type': 'way',
 'osm_id': 353533683,
 'boundingbox': ['35.5912514', '35.594524', '-78.8117411', '-78.8064663'],
 'lat': '35.5928655',
 'lon': '-78.80864240000005',
 'display_name': 'School, Fuquay-Varina, Wake County, North Carolina, United States',
 'class': 'place',
 'type': 'neighbourhood',
 'importance': 0.36}

But I wanted to get list of possible result.

0

1 Answer 1

2

Look at the Taras's answer in Get state but want country in GeoPy and Nominatim:

When you try embedding exactly_one=False parameter (by default it is True) into your code

And in geopy.geocoders.Nominatim.geocode

geocode(query, *, exactly_one=True, timeout=DEFAULT_SENTINEL, limit=None, addressdetails=False, language=False, geometry=None, extratags=False, country_codes=None, viewbox=None, bounded=False, featuretype=None, namedetails=False)

Therefore:

location = geolocator.geocode("School") #= geolocator.geocode("School"), exactly_one=True)
print(location.raw)
{'place_id': 174509566, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 353533683, 'boundingbox': ['35.5912514', '35.594524', '-78.8117411', '-78.8064663'], 'lat': '35.5928655', 'lon': '-78.80864240000005', 'display_name': 'School, Fuquay-Varina, Wake County, North Carolina, United States', 'class': 'place', 'type': 'neighbourhood', 'importance': 0.36}

And

location = geolocator.geocode("School"), exactly_one=False)
for loc in location:
    print(loc.raw)
{'place_id': 174509566, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 353533683, 'boundingbox': ['35.5912514', '35.594524', '-78.8117411', '-78.8064663'], 'lat': '35.5928655', 'lon': '-78.80864240000005', 'display_name': 'School, Fuquay-Varina, Wake County, North Carolina, United States', 'class': 'place', 'type': 'neighbourhood', 'importance': 0.36}
{'place_id': 357867, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'node', 'osm_id': 151422297, 'boundingbox': ['36.9450563', '36.9850563', '-93.4874147', '-93.4474147'], 'lat': '36.9650563', 'lon': '-93.4674147', 'display_name': 'School, Stone County, Missouri, 65675, United States', 'class': 'place', 'type': 'hamlet', 'importance': 0.36, 'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_place_village.p.20.png'}
{'place_id': 167700780, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 318165539, 'boundingbox': ['32.0714473', '32.0741895', '120.8146237', '120.8201063'], 'lat': '32.07294075', 'lon': '120.81740228211956', 'display_name': 'School, 唐闸镇街道, 崇川区, 南通市, 江苏省, 226000, 中国', 'class': 'landuse', 'type': 'construction', 'importance': 0.30999999999999994}
{'place_id': 215092800, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 602663948, 'boundingbox': ['37.0138617', '37.0150821', '26.9460925', '26.9465295'], 'lat': '37.0144836', 'lon': '26.9464163', 'display_name': 'School, Δήμος Καλυμνίων, Περιφερειακή Ενότητα Καλύμνου, Περιφέρεια Νοτίου Αιγαίου, Αποκεντρωμένη Διοίκηση Αιγαίου, 85200, Ελλάς', 'class': 'natural', 'type': 'cliff', 'importance': 0.30999999999999994}
{'place_id': 181158290, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 385516187, 'boundingbox': ['10.771975', '10.7722775', '79.7649394', '79.7653411'], 'lat': '10.7721123', 'lon': '79.7651351889881', 'display_name': 'School, Aliyur, Nagapattinam, Nagapattinam District, Tamil Nadu, India', 'class': 'natural', 'type': 'water', 'importance': 0.30999999999999994}
{'place_id': 209320653, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 578423904, 'boundingbox': ['28.1030218', '28.1035714', '82.2905674', '82.2914013'], 'lat': '28.1033061', 'lon': '82.29098062758565', 'display_name': 'School, Tarigaun, Tulsipur, दाङ देउखुरी, मध्य-पश्चिमाञ्चल विकास क्षेत्र, लुम्बिनी प्रदेश, नेपाल', 'class': 'landuse', 'type': 'residential', 'importance': 0.30999999999999994}
{'place_id': 168760433, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 319925177, 'boundingbox': ['20.7521232', '20.7529092', '-105.2560172', '-105.2553867'], 'lat': '20.752511849999998', 'lon': '-105.2557026180828', 'display_name': 'School, San Vicente, Bahía de Banderas, Nayarit, México', 'class': 'landuse', 'type': 'commercial', 'importance': 0.30999999999999994}
{'place_id': 218867956, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 624407053, 'boundingbox': ['7.480552', '7.4819875', '3.9080287', '3.909494'], 'lat': '7.4812069', 'lon': '3.908693944912778', 'display_name': 'School, Sasa Market, Akinyele, Oyo, Nigeria', 'class': 'landuse', 'type': 'commercial', 'importance': 0.30999999999999994}
{'place_id': 246268194, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 781113363, 'boundingbox': ['-13.6284285', '-13.6241848', '29.0467927', '29.0498197'], 'lat': '-13.626255950000001', 'lon': '29.048202796816035', 'display_name': 'School, Mkushi District, Central Province, Zambia', 'class': 'landuse', 'type': 'residential', 'importance': 0.30999999999999994}
{'place_id': 242730699, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 778514086, 'boundingbox': ['-13.5496012', '-13.5475416', '28.9063684', '28.9090694'], 'lat': '-13.54840955', 'lon': '28.9077512070212', 'display_name': 'School, Mkushi District, Central Province, Zambia', 'class': 'landuse', 'type': 'commercial', 'importance': 0.30999999999999994}

 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.