Create Google Map mashups with Flickr photosets

Over at Frame Digital we've been working on a new tool to create embeddable google maps using photos from Flickr users. Its one of those often touted mashups, its designed to be easy to use and we hope it will be useful for people who can't create these sort of things themselves. Its got loads of features, such as multiple map creation (registration required) custom photo dimensions, color palettes, map size, the list goes on.

There's a few tools out there that already do this sort of thing such as mapbuilder.net and MyPicsMap, but we think MapFlickr has some different features that make it stand out. If you want to see more Google map toys, Mashable has a great list.

The best way to understand it is to use it, head over to imapflickr.com and have a play. Just remember, your photos need to have geolocation information added to them before it will work!

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Easy Flickr and Google Maps Mashups

I'm been using the Google Maps API for a few years now on various projects. Developer nirvana is often being able to integrate different APIs to get an entire entirely different project. Like for example merging Flickr geo-located photos onto a Google Map.

Recently my company released a website allowing registered users to upload photos and videos using their online control panal to store files on Flickr and YouTube. We used the excellent Flickr.NET wrapper and Google's own .NET class library for the YouTube integration. Approval of images and videos were done using a custom CMS tool on the website allowing content editors to preview the multimedia uploads before making them visible, using calls to the respective APIs to change permissions. It worked pretty well, although uploading large video files is definitely something your average user still struggles with. You can see the end result here.

While trawling the internet trying to figure out how to implement the various API integrations I came across a website at mapaset.4bcj.com that allows you to create your own Flickr/Google Maps mashup without doing any coding at all. Its basically a clever mashup wizard. I think its part of Brett Jones blog, but there's very little information about it.

The UI could maybe do with a bit of work, but its a great idea. I really like how the application can use different ways to access your photos, such as username, email address or even the URL to your photostream. Very clever and generated results are pretty good. Here's an example of it using the code generated on the site to show a bunch of photos from recent trip to Laos.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

A C# Wrapper for Google's Static Map API

I originally published this article on Codeproject.com

Example Google Maps static image

Introduction

Unless you've been living on Mars for the past 4 years, you'll probably know about Google Maps and the rich API the lovely folks at Google have exposed, allowing all sorts of clever interactive mapping experiences that developers all over the world have been bringing to the masses.

In February 2008, Google went low key; it removed the JavaScript and the fancy API interface from Google Maps, and introduced the Google Static Maps API, allowing users the ability to generate a map as a regular image. It can still have markers and polylines, but is displayed as a static image, such as a JPEG, GIF, or PNG.

This article aims to explain how to use C# to implement the static images API using a fairly straightforward wrapper. If you've ever used the Google Maps API, this will be easy.

Cool, I get it, and I want some static map action on my website. Where do I start?

The static API is really, really easy to use. First off, you'll need a Map API key from Google. The one being used in the included demo code is for localhost.

You create a static map by adding an image to your HTML page. Then, by specifying a bunch of parameters in the image URL querystring, you can set the image size, location, zoom level, and a bunch of other parameters. The full spec is here.

In its simplest form, you can just create a static map by adding an image to an HTML page, and provided you have the correct information in the image URL querystring, you'll be able to add a map to a website.

Okay, thanks for that, can I go now?

Uh, no. Adding images using a parameterized URL is all good and well, but in the real world (well, my world at least), I really don't want to be messing around with querystrings. They are so 1995. If I have a large content managed website with 1000 geolocated points, I don't want to have to generate all that querystring information manually, it's way too prone to errors. I want databases, I want geocoded points, I want structure, in fact, what I need is a wrapper in C# that can handle the Static Maps API, then I can forget about querystrings, pipe-delimited parameters, and 1000 image URLs full of errors.

Using the code

A static map consist of two parts: the properties of the map image itself, such as the size, the zoom level, and the location, and the information displayed, which is a collection of markers and paths (static polylines for you gmapping aficionados). This article doesn't cover paths, the implementation is similar to adding markers. I might add it at a later date if people ask.

So, let's look again at a basic map with a marker attached:

To represent this in .NET then, we need a class containing a map, with properties defining the image dimensions, zoom level, centre point, and we need a class that contains the marker information (size, position, color, optional character).

Here's a class diagram that should cover it (I've edited this slightly to better fit on-screen):

StaticMap class diagram

Each map has the following properties:

  • APIKey - Obtainable from Google, and required to render a map.
  • Height: Image height in pixels.
  • Width: Image width in pixels.
  • LatCenter: The central latitude point of the map (the 'Y' axis).
  • LngCenter: The central longitude point (the 'X' axis).
  • Type: Mobile or Roadmap. The mobile maps generally use less key lines around roads, and often have more street names for the equivalent zoom level.
  • A generic list of Markers. The nested Marker class contains information for each marker, such as the Lat/Lng points, marker size, color, and optional single character identifier (such as a letter or number).

Properties such as a the marker color, size, etc. are simply defined as enums - if Google adds any more colors or sizes at a later date, it is easy enough to extend.

For example, this code will create the image displayed in the article introduction:

// create new map object
var marker = new StaticMap.Marker();

var map = new StaticMap
{
	Width = 175,
	Height = 175,
	Zoom = 15,
	LatCenter = 55.8592110,
	LngCenter = -4.2466380
};
// add marker to centre point
marker.Lat = map.LatCenter;
marker.Lng = map.LngCenter;
marker.Size = StaticMap.mSize.Normal;
marker.Color = StaticMap.mColor.Purple;
marker.Character = "1";
map.Markers.Add(marker);

// render map
imgMap.ImageUrl = map.Render();

Ultimately, on calling the Render method, the StaticMap class mashes together all its properties and its list of markers to generate a single parameterized URL used for generating a static map.

<img id="ctl00_ContentMain_imgMap"
src"http://maps.google.com/staticmap?center=55.859211,-4.246638&zoom=15&
size=175x175&maptype=roadmap&markers=55.859211,-4.246638,purple1&key="/>

I've included three examples in the downloadable demo that should explain how to use the class. It could be encapsulated into a usercontrol, or plugged into a larger CMS system where users get to position their point on a map, and choose the color and size of the markers. The only limit is your imagination.

In summary

The Static Maps API is a nice, simple way of creating Google maps that can be used in a multitude of places where a full blown, interactive, JavaScript enabled version just isn't required. Hopefully, this wrapper will make it easier for you to add them to your own projects without resorting to messing with querystrings.

History

Demo project updated to include a solution that will run with .NET Framework v2.0, on Visual Studio 2005. I no longer have VS2005 installed, so there may be some issues with the 2005 solution file. The code however, will compile and run using the correct framework.

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,