Open In App

Python | Calculate geographic coordinates of places using google geocoding API

Last Updated : 15 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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
 
# 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 | Reverse Geocoding to get location on a map using geographic coordinates
Reverse geocoding is the process of finding a place or a location address from a given pair of geographic coordinates(latitude and longitude).Modules needed: reverse_geocoder: A Python library for offline reverse geocoding. pprint: A module which helps to "pretty-print" any arbitrary python data structure. Installation: The modules can be easily in
1 min read
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 with summary information about each place; additio
3 min read
Calculate distance and duration between two places using google distance matrix API in Python
Google Map Distance Matrix API is a service that provides travel distance and time is taken to reach a destination. This API returns the recommended route(not detailed) between origin and destination, which consists of duration and distance values for each pair. To use this API, one must need the API key, which can be get form here. Modules needed
2 min read
Python | Calculate Distance between two places using Geopy
GeoPy is a Python library that makes geographical calculations easier for the users. In this article, we will see how to calculate the distance between 2 points on the earth in two ways. How to Install GeoPy ? pip install geopy Geodesic Distance: It is the length of the shortest path between 2 points on any surface. In our case, the surface is the
1 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 page. To use this service, one must need an API key
2 min read
Build a GUI Application to get distance between two places using Python
Prerequisite: Tkinter In this article, we are going to write a python script to get the distance between two places and bind it with the GUI application. To install the GeoPy module, run the following command in your terminal. pip install geopy Approach used: Import the geopy module.Initialize Nominatim API to get location from the input string.Get
2 min read
Displaying the coordinates of the points clicked on the image using Python-OpenCV
OpenCV helps us to control and manage different types of mouse events and gives us the flexibility to operate them. There are many types of mouse events. These events can be displayed by running the following code segment : import cv2 [print(i) for i in dir(cv2) if 'EVENT' in i] Output : EVENT_FLAG_ALTKEY EVENT_FLAG_CTRLKEY EVENT_FLAG_LBUTTON EVENT
3 min read
Parallel Coordinates Plot using Plotly in Python
A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization library. Parallel Coordinates Plot Parallel coordinates
2 min read
Python - K length decimal Places
In Python, controlling the number of decimal places in your numeric values is essential for presenting results accurately and efficiently. This article explores techniques to manage K-length decimal places in Python. Given a Decimal Number, extend its digits to K length. Input: num = 76.8, K = 5 Output: 76.80000 Explanation: Length of decimal place
3 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() + float() + split() + map() The combination of above fun
5 min read
Article Tags :
Practice Tags :