Python | Calculate geographic coordinates of places using google geocoding API
Geocoding is the process of converting addresses into geographic coordinates like latitude and longitude, which can be used to mark position on map.
To use the Google Maps Geocoding API, one must need an API key, which can be get form here.
Modules needed :
import requests
import json
Below is the implementation :
# Python program to calculate geographic # coordinates of places using google # geocoding API # importing required modules import requests, json # enter your api key here api_key = 'Your_api_key' # url variable store url # take place as input place = input() # get method of requests module # return response object res_ob = requests.get(url + 'address =' + place + '&key; =' + api_key) # json method of response object # convert json format data # into python format data. x = res_ob.json() # print the vale of x print(x) |
chevron_right
filter_none
Output :
Dehradun
{'results': [{'address_components': [{'long_name': 'Dehradun', 'short_name': 'Dehradun', 'types': ['locality', 'political']}, {'long_name': 'Dehradun', 'short_name': 'Dehradun', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'Uttarakhand', 'short_name': 'UK', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'India', 'short_name': 'IN', 'types': ['country', 'political']}], 'formatted_address': 'Dehradun, Uttarakhand, India', 'geometry': {'bounds': {'northeast': {'lat': 30.4041936, 'lng': 78.1089305}, 'southwest': {'lat': 30.2466633, 'lng': 77.92533879999999}}, 'location': {'lat': 30.3164945, 'lng': 78.03219179999999}, 'location_type': 'APPROXIMATE', 'viewport': {'northeast': {'lat': 30.4041936, 'lng': 78.1089305}, 'southwest': {'lat': 30.2466633, 'lng': 77.92533879999999}}}, 'place_id': 'ChIJr4jIVsMpCTkRmYdRMsBiNUw', 'types': ['locality', 'political']}], 'status': 'OK'}
Recommended Posts:
- Python | Reverse Geocoding to get location on a map using geographic coordinates
- Python | Calculate distance and duration between two places using google distance matrix API
- Python | Get a set of places according to search query using Google Places API
- Python | Calculate Distance between two places using Geopy
- Python | Get a google map image of specified location using Google Static Maps API
- Calculate n + nn + nnn + ... + n(m times) in Python
- Python program to calculate age in year
- Python | Calculate difference between adjacent elements in given list
- Python | Pandas Series.mad() to calculate Mean Absolute Deviation of a Series
- How to download Google Images using Python
- How to run Python code on Google Colaboratory
- Python Program for Program to calculate area of a Tetrahedron
- Python | Plotting Google Map using gmplot package
- Performing Google Search using Python code
- Python | Plotting Google Map using folium package
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



