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.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Wiremock How to easily mock REST / SOAP or any other API

How images on your website can be optimised in less than 10 minutes

Data Structures | Stacks, Queues, and LinkedLists

SPARKIFY Customer Churn Prediction

Getting started with RealityKit: Collisions and other Events

Microsoft Word 2011 Mac Crack

Maximize your experience at TOHacks 2021 Boot camps

TOConnect — Fostering the leaders of tomorrow

Edit a website content in your browser

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Nielsen

Chris Nielsen

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

More from Medium

Journal 144 — Unity Project Development, 2.5D Shooter

A Series On Creating Immersive Audio in Unity with Custom Wwise Scripts

Making a RTS game #42: Designing our main menu 1/2 (Unity/C#)

How to Remove a Large File from Commit History in Git?