In this recipe, we are going to learn how to use the Foursquare API, and populate a Mapbox base map with Foursquare data. We are going to populate the map with venues as we pan and zoom.
The following steps need to be performed:
Create a developer account at Foursquare.
Create a new app to get your client ID and client secret.
Construct a request to the Foursquare venues endpoint. Make sure that you are passing either the latitude and longitude using the
ll
parameter, or a city with thenear
parameter.The
query
parameter with a venue category, and thev
parameter for the API versioning are also required.Once the request is constructed, use jQuery's
getJSON
function to call the endpoint.Enumerate through the returned results, and for each venue, create a new marker.
Add all the markers to a new layer, and add the layer to the map.
Foursquare has a public API that is free to use as long as you have a developer account. It's a RESTful API, and using...