Setting up the Google Places API service

Since we have already imported the updated scripts, setting up this new service should be a breeze for us now. Perform the following instructions to set up and test the GooglePlacesAPIService:

  1. Go back to the Unity editor. Drag the Map scene into the Hierarchy window from the Assets folder in the Project window.
  2. Expand the MapScene and Services object in the Hierarchy window.
  3. Right-click (press Ctrl and click on a Mac) on the Services object, and from the context menu select Create Empty. Rename the new object GooglePlacesAPI.
  4. Drag the GooglePlacesAPIService script from the Assets/FoodyGo/Scripts/Services folder and drop it onto the GooglePlacesAPI object in the Hierarchy or Inspector windows.
  5. Right-click (press Ctrl and click on a Mac) on the MapScene object in the Hierarchy window, and from the context menu select Create Empty. Rename the new object PlaceMarker.
  6. Right-click (press Ctrl and click on Mac) on the PlaceMarker object in the Hierarchy window, and from the context menu select 3D Object | Cylinder.
  7. Drag the new PlaceMarker object into the Assets/FoodyGo/Prefabs folder to make it a new prefab. Leave the original object in the scene but deactivate it by unchecking the checkbox beside the objects name in the Inspector window.
  8. Select the GooglePlacesAPI object. Drag the PlaceMarker prefab you just created onto the empty slot for the Place Marker Prefab slot.
  9. With the GooglePlacesAPI object still selected, fill in the properties, as shown in the following screenshot:

    Setting up the Google Places API service

    Google Places API Service configuration

  10. Ensure that you enter the key you generated for the API key, in the previous section.
  11. Right-click (press Ctrl and click on a Mac) on the Map scene, and from the context menu, select Remove Scene. Ensure that you save the scene when prompted.
  12. Press Play to run the game in the editor and make sure that the GPS service is set to simulate. If you are still using the Google headquarters (37.62814, -122.4265) as your simulation start location, then you should see plenty of place marker cylinder objects spawn around the character.

Note

If you are not using the Google coordinates in your GPS simulation and not seeing any locations, ensure that you try a location close to lots of restaurants, grocery stores, or any other place related to food. Of course, if you continue to experience troubles, refer to Chapter 10, Troubleshooting.

With the places service running, the player can now see new objects around them. We won't allow the player to interact with those objects, yet. However, we certainly don't want a plain old cylinder representing those markers either. What we need to do is create a much better-looking marker, and we will do that in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.126.241