For Example This Url: https://goo.gl/maps/5URZH1fAZ6S6Ew2k9
How Can We Extract Latitude And Longitude ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
You can use OpenStreetMap to retrieve the latitude/longitude for an address or city. For example:
def get_coordinates(self, address):
# Define the API endpoint and parameters for the API request
endpoint = 'https://nominatim.openstreetmap.org/search'
params = {
'q': address,
'format': 'json',
'addressdetails': 1,
'limit': 1,
# (Optional) country codes separated by a comma (e.g., 'de,gb')
'countrycodes': 'gb'
}
# Send the API request and get the response
response = requests.get(endpoint, params=params)
data = response.json()
if data:
return (data[0]['lat'], data[0]['lon'])
else:
return False
If you want to parse the url you can use something like below which returns the full url:
import requests
def get_full_url(self, short_url):
try:
# Make a request to the short URL with allow_redirects=False
# to prevent the requests library from following the redirect
response = requests.head(short_url, allow_redirects=False)
if response.status_code in [301, 302]:
return response.headers['Location']
else:
return None
except Exception as e:
return None
I hope this helps!
Thank you, But the question was how to retrieve latitude/longitude for a shared URL (https://goo.gl/maps/5URZH1fAZ6S6Ew2k9) not for an address
let's say i have a field "location_url", in this field I paste the url of a place that I have received from someone, and onchange this field i update the longitude and latitude fields.
In that case I misunderstood. You can use the code in the updated answer. You only have to parse the longitude and latitude from the url, e.g., re.search(r'@(-?\d+\.\d+),(-?\d+\.\d+)', url)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
0
May 25
|
281 | ||
|
2
Apr 25
|
2461 | ||
|
1
Feb 25
|
809 | ||
|
2
Feb 25
|
1312 | ||
|
2
Jan 25
|
1439 |