Journal 127 — Unity App Development, Google Maps API

Objective: To set up the Google Maps API to embed a map in an app

In the previous articles, I started setting up an app to collect information related to tracking insurance claims. In this article, I will go over the setup using Google Maps Static API to show a static map within the app.

After going through the start procedure, you will be issued an API key which needs to be used as part of the map request.

In the Location Panel script, we can first create a variable to store the API Key.

Construct Google Maps URL

Per the Google Maps Get Started page, the URL to show a static map should be in the following format:

The URL parameters include several options for location (center, zoom level), map parameters (image size, scale, map type, language, region), feature parameters, and key and signature parameters.

Here’s one example from Google and how the parameters are used:

Here’s another example, which is closer to the style we can use. We will end up converting the location to latitude and longitude format.

So back in the Location script, we’ll copy one of the examples and start setting up the base URL and the parameters to track.

We’ll add in variables for each parameter and build the entire URL.

Add Address Bar

Before adding in the URL Request, I want an address bar above the map to give the user an option to enter in a standard address format and confirm it is to their liking before proceeding, whether it is simply City & State or a full address. For some additional features, I will eventually add markers to the map results, and also give options for a more zoomed in or zoomed out map.

Send out URL Request

Now that we have the URL for the map location, we need to make the URL request with UnityWebRequestTexture.GetTexture(URL). We can then change the map texture to the static map downloaded from Google Maps.

Now let’s see this in action.

Thank you for your time!

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.