 This is a quick tutorial on how to get a Google map into a Unity game, and in my example I'm doing a 2D side scrolling game, and I want the map to show up in the Canvas layer, in the UI layer, not on like a 3D object or an actual game object within the scene. So you can see, if I push play here, this is my game, and you know my map is showing up in the bottom right here, I've got a little scrolling text box that I need to do some work on, and these all sit above the actual scene, you know, they're following the character around wherever he goes, and he's doing his funny animations and stuff like that. So anyway, I'm going to show you how I set that up. The first thing that you need to do is have a Canvas element, you know, you can create those by going to UI, Canvas, and that's just a root element for any sort of UI components you want to have. So all of my UI components sit inside that Canvas. I have the updates panel, which was that text box that showed up in the upper right, and then I have my map game object, which is this box here. So this is the updates panel, and this is the map. Don't need to worry about the updates panel right now. So within that map, I have an image, which is just this sort of transparent white box, and within that, I have another game object, which I called map scroll view. And the reason I have this is because I want, if my Google map tile is larger than the viewable area, I want to be able to scroll around. It's not required, but you know, it's useful in my case. So anyway, I've attached this scroll rect component. I've allowed it to be able to scroll horizontal and vertical. I've given it this elastic bounce motion when it reaches the ends. I could just have it be clamped. So when it hits the edges, it doesn't sort of bounce. In fact, I might like that better. And then I've got this rect mask, which basically just sizes itself to this rect transform. And anything that goes outside of this rectangle, it just masks off. Now within that scroll view, nested here, I've got an image component. So that also has a rect transform. I've set it to the size that I'm going to be pulling in my Google map tile app, which is 640 by 640. And then I've got this raw image tag, which I just added component, which I just added via the add component for raw image. Now, notice there's also an image component within Unity. The difference between raw image and image is that image only accepts a sprite type, and raw image accepts any kind of texture. So what we're going to be doing is the Google map tile will be coming in as a texture. We're applying a texture to the raw image. If we applied it to an image, it wouldn't show up. As far as you can correct me if I'm wrong. Anyway, the last thing I've done is attach this map script. And that's what we're going to go through next. But basically the map script allows us to query Google maps and get our map tile. So in this map script, you can see we're giving it a latitude, a longitude, a zoom level, the map width and height, which is again the texture size that we want to bring it in at. And then the type of map we want. So there's roadmap, satellite, view, hybrid, or terrain. We could customize that even more and do some kind of custom map style. We could add markers and things like that. But we're just going to leave it simple for now as a roadmap, which is the most common type of Google map. I'm also going to show you later how to change that latitude and longitude if you want to kind of update the map with a new style. So this is our map script. This is the common, you know, these are, I'll put these first, but these are the common libraries that come in with any script. And then I've added this unityengine.ui library, which is the library you need to do any sort of updates or changes to UI elements within Unity. We've got this variable, which is going to hold the post request to Google Maps. We've got again our latitude and longitude, which are static right now. We can change it within the Unity UI as you saw, or zoom level, or tile size, our map type, which is an array, and then the scale. We've got this variable, which I'm actually not using right now called loading map. This would be useful if there were other things in your scene that needed to change or like a message to display to let the user know that it's waiting to load the map. And once the map is loaded, this will be set to true. So in order to get the map tile, we need a, what's called a coroutine, which is essentially a separate thread, a separate process that Unity cycles through outside of this sort of update loop. So that way, it doesn't block any of the other things that are happening within your game. So your game can keep track of your characters, animations, and things like that while the map is still loading. And so I've got this variable here called map coroutine, and that's going to hold this function. It's just going to be a reference to this function so that we can stop it, start it. So on start, when the script loads, we're going to say that map coroutine variable is equal to this function, get Google map. And it takes two parameters. These are floats. They're numbers, decimal numbers, which are the latitude and longitude coordinates. Anyway, within start, we're going to start that coroutine. So the coroutine specifies the URL to the Google Maps API. And so basically Google allows you to get these tiles via their API. But the first thing that you need is your key. And in order to do that, you need to visit the Google Maps API page. I'll post that link. But once you do so, you need to sign up for a key. And basically, it ties it to a Google map account. You agree to their terms. And you set up an application that you're going to use this API key for. And then it gives you this key value here. And we're just going to paste that into the script here. And then use our zoom map with height scale, latitude and longitude variables in order to construct the API request. So Unity provides this www class. And that allows you to create these get and post requests. If you're a JavaScript developer, web developer, you might recognize them as similar to an Ajax request. And so we construct that request. We return it once we've successfully queried the API. And then we get our game object and select the raw image component. And apply the texture that's returned from Google Maps. So once we have that map texture, we stop the coroutine. Say we want to update the map with a new latitude and longitude. I've got the Unity standard update function here. And I just, you know, we could make this dynamic allow the user to maybe, I don't know, type in their latitude and longitude. But I've just set up a simple static latitude and longitude that we're going to update our map with. And I'm basically just saying if they hit the key M on the keyboard, let's update the map with this new latitude and longitude. Now notice the format on this. It's a float number. There's various types of formats for latitude and longitude. And the one that I started with actually was from Flickr. I'm taking exit data from Flickr for different photos. So this would be data stored in a camera. If you look at it, you can see GPS latitude 40 degrees 41. I don't know what they call it feet and minutes or something like that. Then you've got your longitude here, which is a degree west. So I needed those numbers to be translated into a format that Google understands. And in order to do that, I just did a Google search from this site, earthpoint.us. And I posted in that number with degrees, minutes and seconds north and west. And what that rendered out is various, you know, the various other formats that latitude and longitude can be listed in. And the one that I wanted was this decimal number here, this first one. And you see that it's turned that west degree into this number, a negative number. I'm just copying those in. See that one's there. Longitude is here. And I'm adding the F at the end to let Unity know that it's a float, floating point number. And then I'm just updating that I'm re specifying that coroutine as get Google map with the new latitude and longitude and then restarting that code. So now if I go back into my scene, push play, I've got my regular map, I hit the M key. And you can see our map now sets us in ozone park in New York City. So that is basically the process of getting a Google map into Unity game.