Places API Nearby Search

Google Maps API Javascript

Nearby Search Request is part of the Google Places API Library.

It allows searching for different types of places such as restaurants, grocery stores, etc based on the user’s current location.

HTML5 Geolocation

Get User Location using HTML5 Geolocation in the form of Latitude and Longitude.

     position => {
     error => {

Nearby Search Base URL

Hey, Like what you're reading?

🔥 1,750+ students already enrolled!
4.5 ⭐️⭐️⭐️⭐️⭐️ (86+ ratings) BEST SELLER

Request URL Parameter (Required)

JSON or XMLOutput format (json recommended)

Request Query Parameters (Required)

keyYour API Key from Google Cloud Platform. Find how to get it here.
locationThe value must be specified in the format of latitude, longitude.
radiusSpecify in meters. i.e. 5000 = 5KM
typeThis could be a restaurant, bar, etc. full list here.

Optional Query Parameters

rankbydistanceThis will sort places in ascending order by their distance. When using rankby, the radius option can’t be used.

Sample Request URL to Nearby Search[YOURAPIKEY]&location=-33.8670522,151.1957362&radius=5000&type=restaurant

Nearby Search Response JSON Object

Once the request is complete, it will return a response object in a JSON format like the screenshot below and it will have 20 places inside the results array.

Get Next 20 Places

As you know, Nearby Search Request gives you only 20 results in the response object per request.

To get the next 20 results, we’ll need to add an additional query parameter called pagetoken to the URL.

And the value of this param can be found in the previous response object under the property called next_page_token like the image below.

So the sample request URL would be like this.[YOURAPIKEY]&location=-33.8670522,151.1957362&radius=5000&type=restaurant&pagetoken=CqQCFQEAAKQ48fsO4kjIu

You can get the maximum of 60 places using Nearby Search Request.