Google Maps Static API in Dynamo

image by Google

Every now and then I find myself roaming the internet looking for things to do. Oh yeah, I know, I shouldn’t be saying this out loud. If there is a thing that I miss about working in an architectural office, is the abundance of things to do. There were always deadlines, so I could just model something out of pure boredom. There was always a backlog of ideas that I stumbled upon while working on a project, that I could always reach back into and have some fun. Those days are gone. One thing that you learn to do as a self employed consultant is to focus a little more on the work that actually pays the bills. Yeah, there is always that threat of starvation hanging over your head, that kind of makes you want to work on things that pay your bills, instead of messing around with Dynamo for shits and giggles. Anyways, every now and then I do, and when I do, I usually get some ideas from a Dynamo Forum. Here was a question:

Can we use Dynamo to get an image from Google Maps, so I can speed up the process of starting up my projects?

You know, that page that every architect makes when they start the project. It should only take a few minutes, but for some reason you spend half a day dicking around with Google Maps, Photoshop and god know what else. So I decided to look into it. Lo and behold there is an API in Google Maps, just for that kind of thing. Who would have thought? Now I just had to implement it for Dynamo. Here’s a few steps, and some options, that are available to us in order to download a PNG snapshot of a map from Google Maps.

So first things first. This is Google Maps API that we are using here to access images of a map. The first requirement with that is that we need to obtain an API Key. What is that you might ask? Well, have a look here: How to get a Google API Key. This step is really important, and even more so is to get the right key. From top of my head I think the steps are following:

  • create a project in your account. you have to add billing information to your project since Google Maps API is a paid service. I think costs are minimal – $2/1000 requests. Keep in mind that when you are working in Dynamo these requests can add up pretty quickly especially if you are working in an Automatic mode.
  • Create a new Credential and restrict it to only accept requests from Google Maps Static API. That’s the API we will be using here. You can look at this API.
  • Write down that key because we will be using it in our project.

Once you have that ready to go, we can get started. The GoogleMaps.DownloadMap node takes an input of a authenticated GoogleMaps input, and a MapSettings. Settings is what I want to talk about next:

  • lat/lon – Latitude/Longitude of the location that we want to download a map for. Yes, I know. Lat/Long? Really? Why not just use an address? Yes, that’s an option. I just didn’t implement it yet. We will eventually get around to that.
  • zoom – these are between 1-20. It controls how much the map is zoomed in. Google describes it that a zoom value set to 1 is whole earth while 20 will show you street details.
  • width/height – that’s in pixels, and can be set max to 640px. It can be increased to 1280 if we scale the number of pixels in a map to 2 using the scale option.
  • scale – please read above. default is 1, but can be set to 2.
  • imageFormat – type of image that you want to download. PNG is default, but you can also get uncompressed JPGs for example.
  • mapType – roadmap is default, but terrain and satellite options are available.

More information about these options can be found here: Map Settings.

The rest of the script is just me getting the downloaded map, and importing it back into Revit. We already had nodes for that from my previous write up, so I didn’t have to do much work on this front. All in all we can get a similar result in just a few mouse clickc:

I hope this helps the gentleman that was looking for a quicker way to access images from Google Maps, and as always please head over to GitHub with any comments or bugs. I will be happy to help.

As usual the sample file will be made available for download for my Patreon supporters, and for everyone else, please follow the images and comments above.


Support archi-lab on Patreon!

Leave a Comment