Scrape data from google maps using swift and google maps places API

The “Places Search” in “Google Places API” enables you to retrieve list of places along with summery information about each place the out put can be either retrieved in JSON or XML format.

Follow the steps to scrape data

Step 1. Building URL with required parameters.

The required parameters are

API key - Key is required to make a request and validate the transaction. Find more information on how to get a key in the below link.

Input Type - Such as search term , latitude and longitude that identifies the search target and search criteria. And radius which defines how much area you want to scrape data in and around the defined latitude and longitude. The google places API limits the distance of 5000 meters to each API request made.

Please look at the following code to know how to construct a URL for making a request.

Building URL for making request.

Step 2. Make a HTTP request to get the data.

In Swift we use class URLSession to provide and API for downloading data and uploading data to endpoints indicated by URL.

We are using google maps url endpoints. Using the function getData(from url: String ) we pass the url into the function

URLSession.shared.dataTask with completion handlers

Shared class is used with URLSession to provide a shared singleton session object that gives you a reasonable default behavior for creating tasks.

dataTask(with: ,completionHandler: )

Creates a task that retrieves the contents of a URL based on the specified URL request object, and calls a handler upon completion.


An object that decodes instances of a data type from JSON objects.

Step 3. Parse json files with decodable protocols and structure

The completion handler contains data response and error. This data is needed to be parsed into json format. You can choose between the data to be parsed from the server. The above code performs parsing of data from the server.

Find full code in repository in the below link




Tech enthusiast i write blogs on Web Development and Mobile app development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

In-Depth: What Makes Agile Transformations Successful?

Distributed Computing for Not-So-Big-Data

Live a pure (function) life

Connection between C# and MYSQL

Everything's connected, yes, that too

BlueJay: A Simple Twitter Bot Written in Python

OutSystems BPT — Timeouts and exceptions in ‘Light Processes’ — Part I

<TL;DR> After five years working to define & build a world of spatial computing at Magic Leap, I…


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshay Devkate

Akshay Devkate

Tech enthusiast i write blogs on Web Development and Mobile app development.

More from Medium

Parkinson’s Disease Observation — Exercise/Tremor Analysis

The Best Tutorial For Starting Learning iOS Development

How To Send Images in The Notification Payload — Firebase

Long-running Cloud Run functions