5

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.

Anonymous
  • 61
  • 1
  • 8

2 Answers2

11

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)
Hermawan Wiwid
  • 415
  • 5
  • 14
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

vey
  • 101
  • 8