i have google map short link like this : https://maps.app.goo.gl/wsmXZrYfP8V3ur2RA
i want python script to ask user to input google map link , then print X and Y
i user input : https://maps.app.goo.gl/wsmXZrYfP8V3ur2RA
python code will get full link (https://www.google.com/maps/search/29.996966,+68.748251?entry=tts&g_ep=EgoyMDI0MDUyOC4wKgBIAVAD)
then print
x= 68.748251
y=29.996966
import requests
from urllib.parse import urlparse, parse_qs
def get_coordinates(google_map_short_link):
# Fetch the full Google Maps link
response = requests.get(google_map_short_link)
if response.status_code != 200:
print("Failed to fetch the full link.")
return None
# Extract the full link from the response
full_link = response.url
# Parse the URL to extract latitude and longitude
parsed_url = urlparse(full_link)
query_params = parse_qs(parsed_url.query)
coordinates = query_params.get('q')
if coordinates:
coordinates = coordinates[0].split(',')
if len(coordinates) == 2:
return coordinates[0], coordinates[1]
return None, None
def main():
# Ask user for Google Map short link
google_map_short_link = input("Please enter the Google Maps short link: ")
# Get coordinates
x, y = get_coordinates(google_map_short_link)
# Print coordinates
print("x =", x)
print("y =", y)
if __name__ == "__main__":
main()
New contributor
saqer.ms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.