How do I find correctly the location of my phone using python and geocoder?

3.3k views Asked by At

I wrote a python program that is able to detect my country and type of Network I use, however, the longitude and latitude show up the same, regardless of when I change the phone number, it is not even in my country.

Here is my code.

import phonenumbers
import folium
from target import number
from phonenumbers import geocoder
key = '8d1df9276d2445c5a93c8b12ce962b1e'


theNumber = phonenumbers.parse(number)

yourLocation = geocoder.description_for_number(theNumber, "en")

print(yourLocation)


#Other details

from phonenumbers import carrier
service_provider = phonenumbers.parse(number)
print(carrier.name_for_number(service_provider, "en"))

from opencage.geocoder import OpenCageGeocode
geocoder = OpenCageGeocode(key)
query =str(yourLocation)
results = geocoder.geocode(query)
#print(results)

lat = results[0]['geometry']['lat']

long = results[0]['geometry']['lat']

print(lat, long)


myMap = folium.Map(location =[lat, long], zoom_start_= 9)

folium.Marker([lat , long], popup=  yourLocation).add_to(myMap)


#html save
myMap.save("myLoc.html")
1

There are 1 answers

3
RJ Adriaansen On

It's a typo issue. This will solve it:

long = results[0]['geometry']['lng']

You'll also need to change zoom_start_ to zoom_start.