Click here to Skip to main content
15,892,839 members
Articles / Web Development / XHTML

A C# Wrapper for Google's Static Map API

Rate me:
Please Sign up or sign in to vote.
4.56/5 (27 votes)
16 Aug 2008CPOL4 min read 125.4K   5.9K   126  
How to use the Google Static Maps API within .NET.
using System;
using Frameworx.GMap;

public partial class example2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

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

        map.Width = 300;
        map.Height = 300;
        map.Zoom = 15;
        map.LatCenter = 55.8592110;
        map.LngCenter = -4.2466380;

        // add markerss
        marker.Lat = 55.8598393;
        marker.Lng = -4.2480182;
        marker.Size = StaticMap.mSize.Normal;
        marker.Color = StaticMap.mColor.Purple;
        marker.Character = "1";
        map.Markers.Add(marker);

        marker = new StaticMap.Marker();
        marker.Lat = 55.8584424;
        marker.Lng = -4.2457652;
        marker.Size = StaticMap.mSize.Small;
        marker.Color = StaticMap.mColor.Green;
        marker.Character = "2"; // this won't be displayed - marker is too small
        map.Markers.Add(marker);


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

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Other Frame Digital
United Kingdom United Kingdom

Darren James is technical director at Frame Digital, the online arm of scottish advertising agency Frame.

He spends his working day developing content managed solutions for a wide range of clients, and trying to make it look easy. (It doesn't always work)

When not immersed in code, he has an unhealthly obsession with online games, and tries to travel as much as possible.

His current ambition is to find some time to update his company website, in the meantime, you can find more articles on his blog.

Comments and Discussions