Get address from given coordinate using python
Asked Answered
T

2

6

I have some longitude latitude coordinates and I want to convert it to a specific address using Python. Do you know how to do that? Thank you I am new here.

Thirtythree answered 30/3, 2020 at 10:26 Comment(2)
Have a look at geopySubcritical
Related (maybe dup) - #12943394Kollwitz
S
14

The method that you mean called Reverse Geocode. You can use Nominatim (OSM) for free geocode service

from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.reverse("52.509669, 13.376294")
print(location.address)

Or if you wanna get better results, you can use Google Geocode service that requires API Key

from geopy.geocoders import GoogleV3
geolocator = GoogleV3(api_key='Your_API_Key')
location = geolocator.reverse("52.509669, 13.376294")
print(location.address)
Sincere answered 30/3, 2020 at 10:29 Comment(0)
G
2

use geopy, this is a script I made myself, you can use it

from geopy.geocoders import Nominatim
from os import system, name

those are your imports. then you would want to define a clear function, this will come in play later

def clear():
    if name == 'nt':
        _ = system('cls')
    else:
        _ = system('clear')

then define the useragent:

geolocator = Nominatim(user_agent="coordinateconverter")

i have it set as coordinateconverter because this is my project name

then define your address:

address = '42.2817131, -83.7465425'

that was the ann arbor hands on museum address

then actually convert it:

location = geolocator.reverse(address)
print(location)

this is untested code so it may not work, but it should

Gravamen answered 18/9, 2021 at 17:12 Comment(1)
What is the clear() function used for? It’s not used by the code, only defined.Istic

© 2022 - 2024 — McMap. All rights reserved.