Next Previous

Places API Nearby Search

1357

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.

navigator.geolocation.getCurrentPosition(
     position => {
         console.log(position.coords.latitude);
         console.log(position.coords.longitude);
     },
     error => {
         console.log(error.message);
     }
)

Nearby Search Base URL

https://maps.googleapis.com/maps/api/place/nearbysearch/

Request URL Parameter (Required)

namedescription
JSON or XMLOutput format (json recommended)

Request Query Parameters (Required)

namedescription
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

namevaluedescription
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

https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=[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.

Sharing is caring!

Next Previous
🔥$12.00 19.99 LIMITED PERIOD ONLY

Vue.js + Google Maps API for Beginners Course

🔥 992+ students enrolled!
4.9 ⭐️⭐️⭐️⭐️⭐️(22+ ratings)

BEST SELLER

30-day 100% money-back guarantee!