I want to get the latitude and longitude of the companies listed in a dataframe already cleaned but the only information that I have is the name of the company and the country (In this case just UK).
After trying different things I have got some of the lats and longs but not the ones located in UK in most of the cases. This is the code I tried:
base_url= "https://maps.googleapis.com/maps/api/geocode/json?"
AUTH_KEY = "AI**************QTk"
geolocator = GoogleV3(api_key = AUTH_KEY)
parameters = {"address": "Revolut, London",
"key": AUTH_KEY}
print(f"{base_url}{urllib.parse.urlencode(parameters)}")
r = requests.get(f"{base_url}{urllib.parse.urlencode(parameters)}")
data = json.loads(r.content)
data.get("results")[0].get("geometry").get("location") #That works for the first company
df["loc"] = df["Company name for communication"].apply(geolocator.geocode)
df["point"]= df["loc"].apply(lambda loc: tuple(loc.point) if loc else None)
df[['lat', 'lon', 'altitude']] = pd.DataFrame(df['point'].to_list(), index=df.index)
DataFrame with long and lat wrong
I would agree so much any help. Let me know if my explanation is not clear to provide more details. Thank you!