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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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)
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 6 25
|
453 | ||
|
0
thg 5 25
|
535 | ||
|
2
thg 4 25
|
2612 | ||
|
1
thg 2 25
|
941 | ||
|
2
thg 2 25
|
1446 |