Nerd For Tech
Published in

Nerd For Tech

Integrating Google Maps API with Unity

Objective: Get a picture of a map of the user’s location.

The “mighty” Susquehanna River, Harrisburg, PA

To display a map, we first have to get the user’s location from their device. We’ll need to use an IEnumerator method to do so; I’ll use the Start method in this case.

First we’ll make sure the user has allowed our app to access their location.

If we do have permission, we’ll tell the system to start the process. We’ll give the system 20 seconds to get a response before we give-up.

If the system can’t get the location, we’ll report that.

If we do get the location, we’ll save the latitude and longitude.

Regardless of the result, we’ll have to stop the process we started.

Now that we have the location, we’ll call another IEnumerator. We’ll begin by assembling a URL string with all the data we need: the coordinates (the location point will in the center of the map), the zoom (how focused into the location we the result to be), the image size we want, and our Google-assigned Map APIKey.

Then we’ll use a using statement to make a UnityWebRequest that will store the result of the URL as a Texture. (The using statement will clean-up after itself when finished.) We’ll then send the request. If we get an error, we’ll report it. Otherwise, everything worked and we’ll apply our texture to our image, displaying the map for our user!

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

SOLID principles in iOS

Some Useful flutter/Dart Packages that makes our work faster and easier.

How to Get a Canonical URL in Go

GSoC 2020 at OpenMRS | Community Bonding Period

Check the Currency of a Country in Python

How to Convert a Video File to MP4 in C/C++

Craft ideas into reality with SketchUcation Tools

How to find top tech talent?

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
Ryan Sweigart

Ryan Sweigart

An independent Unity Developer.

More from Medium

How to get GIT Bash for Unity

Prefabs in Level Design

Unity camera plugin save image data as bytes

Basic User Interface Implementation