Example 1¶
Synchronously geolocate a query to an address and coordinates
In [ ]:
Copied!
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="demo-notebooks-geopy")
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print((location.latitude, location.longitude))
print(location.raw)
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="demo-notebooks-geopy")
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print((location.latitude, location.longitude))
print(location.raw)
Example 2¶
Asynchronously geolocate a query to an address and coordinates
In [ ]:
Copied!
from geopy.adapters import AioHTTPAdapter
from geopy.geocoders import Nominatim
import asyncio
async def async_example():
async with Nominatim(
user_agent="demo-notebooks-geopy",
adapter_factory=AioHTTPAdapter,
) as geolocator:
location = await geolocator.geocode("175 5th Avenue NYC")
print(location.address)
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(async_example())
loop.close()
main()
from geopy.adapters import AioHTTPAdapter
from geopy.geocoders import Nominatim
import asyncio
async def async_example():
async with Nominatim(
user_agent="demo-notebooks-geopy",
adapter_factory=AioHTTPAdapter,
) as geolocator:
location = await geolocator.geocode("175 5th Avenue NYC")
print(location.address)
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(async_example())
loop.close()
main()