Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've started thinking about how I will go about making a travel diary blog type web application that will be used on an upcoming round-the-world-trip and decided that I will definitely need maps on it. I wanted to do things like display the trip itinerary as a path with markers at each stop, I also wanted to show a zoomed in map of the current travel location. So I needed a way to generate these maps, the most obvious answer was Google Maps, and after a quick search I found exactly what I needed, the Google Maps Static Maps API. This makes static images of the map data, so it won't let you scroll around, etc, but with regard to my project, this is a perfect fit.

There are some quota restrictions and Google recommends that you get an API key, but if you don't use them excessively (less than 25000 requests per day) you should be fine. There are some other restrictions too, notably, the URL to generate the map cannot be larger than 2048 characters. This size restriction means you can't get too fancy with what you create, but it does give a good leeway in terms of customisation.

Anyway with that in mind, here are some examples that eventually work up to the final map that shows the travel path and each of the destination markers.

The first example shows a 300x300 satellite map with the default marker set on my home town.
 Example 1
http://maps.google.com/maps/api/staticmap?zoom=4&maptype=satellite&size=300x300&markers=Brisbane,Australia

staticmap1.png


Working up from this the next example changes the map type to terrain and customises the marker's colour and label.
 Example 2
http://maps.google.com/maps/api/staticmap?zoom=4&maptype=terrain&size=300x300&markers=color:orange|label:1|Brisbane,Australia

staticmap2.png




Now for some paths. I've changed the size of the map to 500x200 so that more of the world is shown and created a path spanning a number of locations. The path colour and weight have been customised too.
 Example 3
http://maps.google.com/maps/api/staticmap?zoom=1&size=500x200&path=weight:3|color:0×0000FF70|Brisbane,Australia|Hong%20Kong|Moscow,Russia|London,UK|Reyjavik,Iceland|New%20York,USA|San%20Francisco,USA

staticmap3.png


That kinda looks ugly with straight lines however. This is easily solved by adding 'geodesic:true' to the path. Instantly the path looks much more familiar and prettier.
 Example 4
http://maps.google.com/maps/api/staticmap?zoom=1&size=500x200&path=weight:3|color:0x0000FF70|geodesic:true|Brisbane,Australia|Hong%20Kong|Moscow,Russia|London,UK|Reyjavik,Iceland|New%20York,USA|San%20Francisco,USA

staticmap4.png


Now using the same locations I created markers (no path). The only change I did to the markers has been to change the colour to orange.
 Example 5
http://maps.google.com/maps/api/staticmap?zoom=1&size=500x200&markers=color:orange|Brisbane,Australia|Hong%20Kong|Moscow,Russia|London,UK|Reyjavik,Iceland|New%20York,USA|San%20Francisco,USA

staticmap5.png


That is not exactly the result that I was looking for since I wanted each of the locations to be numbered. Turns out that is not that simple since each marker customisation has to be separate. The only way to do that is to define multiple markers like below. This greatly increases the size of the URL so be careful.
 Example 6
http://maps.google.com/maps/api/staticmap?zoom=1&size=500x200&markers=color:orange|label:1|Brisbane&markers=color:orange|label:2|Hong%20Kong&markers=color:orange|label:3|Moscow,Russia&markers=color:orange|label:4|London,UK&markers=color:orange|label:5|Reyjavik,Iceland&markers=color:orange|label:6|New%20York,USA&markers=color:orange|label:7|San%20Francisco,USA

staticmap6.png



Now putting it all together, the path and the markers are put into the same URL and we get the final result. I've also changed the map dimensions slightly so more of the world is visible.
 Example 7
http://maps.google.com/maps/api/staticmap?zoom=1&size=515x320&maptype=terrain&markers=color:orange|label:1|Brisbane&markers=color:orange|label:2|Hong%20Kong&markers=color:orange|label:3|Moscow,Russia&markers=color:orange|label:4|London,UK&markers=color:orange|label:5|Reyjavik,Iceland&markers=color:orange|label:6|New%20York,USA&markers=color:orange|label:7|San%20Francisco,USA&path=weight:3|color:blue|geodesic:true|Brisbane,Australia|Hong%20Kong|Moscow,Russia|London,UK|Reyjavik,Iceland|New%20York,USA|San%20Francisco,USA

staticmap7.png


Looks pretty good and ready to be added to my project.

Enjoy!

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Tiny Arcade revision 6 kit assembly and decal application

Jersey JAX-RS filters and interceptors execution order for a simple GET request

How to stop macOS adding shadows to window screenshots

How to run Atari Lynx games on the SNES Classic Mini

Maven dependency scopes with relation to WAR file packaging and the WEB-INF/lib directory

Hacking the Sonoff B1 WiFi LED bulb to run custom firmware

What does an idle WebLogic server run on the hour to cause a CPU spike

How to open the Sonoff B1 wifi LED bulb to access its internal circuitry

Australian release SNES mini classic unboxing and a quick play through

Troubleshooting high CPU usage for JVM threads

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity