-1

This is my code for getting the location of my phone number. I get the GPS location in my country, but not exactly where I am. Is there any way I can fix the code to do so?

import phonenumbers
import folium
from target import number
from phonenumbers import geocoder
key = 'MY_KEY'    

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']['lng']

print(lat, long)


myMap = folium.Map(location =[lat, long], zoom_start= 0)

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


#html save
myMap.save("myLoc.html")
KwameDickson
  • 25
  • 1
  • 5

2 Answers2

0

The phonenumbers library will only return the country name. Using OpenCage geocoder will translate the country name to the position (the center of the country). At no point does either library or service know where you are.

The code follows a tutorial that is shared on a couple of Youtube video. In the videos the presenter is showing a location which they say it's accurate. Or they say they want to protect themselves and use a differnt location. But it's always the center of the country (usually India or Pakistan).

mtmail
  • 1
0

"It's not possible, and it has never been possible to track anyone using the OpenCage API".

https://blog.opencagedata.com/post/we-can-not-convert-a-phone-number-into-a-location-sorry

Read this official article by OpenCage that completely acknowledges that it's never possible, as it is considered unethical.

So please don't try to do that, as it's considered unethical."

  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – Gugu72 Sep 02 '23 at 18:46