Integrating Google Maps API with Unity

Going forward with the panel management of this app I need to set the google maps API to get a static map based on the current location.

To do this you first need a google developer account. Going to this link and following all the steps it will take a few minutes to get our account. Click on the “Get Started” button and follow the steps.

Create a new project, give it a name, and as a product choose Maps. As a result, you should see a pop-up with your API key. Save it in a safe place we will need it in a while.

Let’s go to the script where we want to add the display of the static map.
The goal is to obtain an image to insert in a space that we have previously created. To obtain this image we must construct a URL with certain parameters that we will manage directly from the Unity Inspector.

These parameters are:
- first part of our URL that does not change
- coordinates in latitude and longitude
- zoom of the map
- size or size of our image
- API key we created before

In the code, you can convert the start function in a coroutine by replacing the word “void” with “IEnumerator” as in the following picture, check the geolocation services, and if they are active saved in your latitude and longitude variables. Finally, start the routine that will build your complete URL.

In this coroutine, you will take the data from your URL and save it in your RawImage variable.

Remember to assign the parameters from Inspector and make a build to test the geolocation services directly on your mobile device.

--

--

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
Andrea Alicino

Andrea Alicino

Unity developer and C# programmer. Currently looking for games industry employment.