Python | Calculate geographic coordinates of places using google geocoding API
Last Updated :
11 Jul, 2025
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 :
Below is the implementation :
Python3
# 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
url = 'https://maps.googleapis.com/maps/api/geocode/json'
# 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 value of x
print(x)
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'}
Similar Reads
Python | Get a set of places according to search query using Google Places API Google Places API Web Service allow the user to query for place information on a variety of categories, such as establishments, prominent points of interest, geographic locations, and more. One can search for places either by proximity or a text string. A Place Search returns a list of places along
3 min read
Python | Find Hotel Prices using Hotel price comparison API Makcorps hotel API is used to get JSON data, to compare Hotel prices, ratings, and reviews from more than 200 websites including; Agoda.com, Hotels.com, Expedia and more. It is organized around GET Requests. One can use this API for free to get information for any hotel or any city regarding prices,
3 min read
Find current weather of any city using OpenWeatherMap API in Python The OpenWeatherMap is a service that provides weather data, including current weather data, forecasts, and historical data to the developers of web services and mobile applications. It provides an API with JSON, XML, and HTML endpoints and a limited free usage tier. Making more than 60 calls per min
4 min read
Python | Get a google map image of specified location using Google Static Maps API Google Static Maps API lets embed a Google Maps image on the web page without requiring JavaScript or any dynamic page loading. The Google Static Maps API service creates the map based on URL parameters sent through a standard HTTP request and returns the map as an image one can display on the web p
2 min read
Parsing Json Nested Dictionary Using Python We are given a JSON string and we have to parse a nested dictionary from it using different approaches in Python. In this article, we will see how we can parse nested dictionary from a JSON object using Python. Example: Input: json_data = '{"name": "John", "age": 30, "address": {"city": "New York",
2 min read
Python | Convert location coordinates to tuple Sometimes, while working with locations, we need a lot of data which has location points in form of latitudes and longitudes. These can be in form of a string and we desire to get tuple versions of same. Let's discuss certain ways in which this task can be performed. Method #1 : Using tuple() + floa
4 min read