We will use the Google Places API to populate the virtual world around the player with references to real-world locations or places. Since we already used the Google Static Maps API, adding another service should be straightforward. However, unlike the maps API, the places API is far more restrictive on usage. This means that we will need to undertake additional set-up steps and modify the way we access the service. Not to mention, there will be a direct impact on our business model when we ship.
Another direct competitor to the Google Places API is Foursquare. Foursquare has far fewer restrictive usage limits, but does require additional authentication mechanisms. We will revisit this topic again when we will start Chapter 9, Finishing the Game.
In order to start using the Google Places API, we will need to register and create new API key. This key will allow your app/game to make 1000 queries a day, which isn't very many, when spread over multiple players. Fortunately, if you register for billing with Google, they will bump up your limit to 150,000 requests per day. The code we use in this chapter will attempt to optimize the fewest number of requests so as not to exceed that 1000 request limit in testing.
Open your favorite web browser, and perform the following instructions to generate a Google Places API key:
Getting a Google developer key
Creating a new Google Places API project
Example key, intentionally obscured
Now that you have your API key, let's test out the REST service that is the Google Places API. This exercise will not only show us what information comes back in a search, but will also help us understand the API. Follow the exercise instructions here:
yourapihere.com
text field, as follows: https://maps.googleapis.com/maps/api/place/nearbysearch/json.
type
and value as food
. The following is the table defines the parameters and the values that should be used in this exercise:
Name |
Value |
Description |
|
|
The type of place you want to search for. Of course, we will use the term food. |
|
|
The latitude and longitude coordinates, separated by a comma. |
|
|
This is the radius, in meters, of the area to search from the center location. |
|
|
Use the API key that you generated in the above step. |
Adding parameters for the nearby search
Leave your browser open and on the results page. We will come back to explore the output in the next section.
13.59.136.170