0

I am working on PYCharm IDE application for getting address from latitude and longitude and I have also installed phonenumber and geocoder library to the project in PYCharm IDE but unfortunately geocode is not found in phonenumbers.geocoder.

Code

from geopy.geocoders import Nominatim
import phonenumbers
from phonenumbers import geocoder
from phonenumbers import carrier
import folium
from opencage.geocoder import OpenCageGeocode
phone_number = input("Enter a phone number (with country code): ")
phoneNumber = phonenumbers.parse(phone_number)
#geocoder = OpenCageGeocode("503437953c574180b22457c6f764256c")
yourLocation=geocoder.description_for_number(phoneNumber,"en")
query = str(yourLocation)
results = geocoder.geocode(query)
lat = results[0]['geometry']['lat']
lng = results[0]['geometry']['lng']
geolocator = Nominatim(user_agent="geoapiExercises")
location = geolocator.reverse(lat,lng)
print(location.address)

Error is :

Traceback (most recent call last):
File "D:\pythonProject123\Lib\nn.py", line 12, in <module>
results = geocoder.geocode(query)
          ^^^^^^^^^^^^^^^^
AttributeError: module 'phonenumbers.geocoder' has no attribute 'geocode'

Question is:

HOW TO RESOLVE IT?

2
  • Are you using Anaconda? Commented Aug 10, 2024 at 10:02
  • @toyotaSupra : No Commented Aug 10, 2024 at 10:07

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.