Embed Google Maps in C# Application

First check out this post to see how you can retreive the GPS location of your device.

Then you can use following code to display the map in your windows form

String locationString = @"http://maps.google.com/maps/api/staticmap?center=" + lat.ToString() + "," + lon.ToString() + "&zoom=14&size=250x250&maptype=roadmap&markers=color:red%7Clabel:S%7C" + lat.ToString() + "," + lon.ToString() + "&sensor=false";
            //System.Diagnostics.Process.Start(locationString);
            TaxiLocation loc = new TaxiLocation();
            //loc.WriteHtml(@"http://maps.google.com/maps/api/staticmap?center=6.938905,79.878149&zoom=14&size=250x250&maptype=roadmap&markers=color:blue%7Clabel:S%7C6.938905,79.878149&sensor=false");
            loc.WriteHtml(locationString);
            webBrowser1.Url = new Uri(@"d:myMap.html");

Taxi Location Class

    class TaxiLocation
    {


        public void WriteHtml(String Maps)
        {
            string htmlDocument = @"";
            FileStream fs = File.OpenWrite(@"d:myMap.html");
            StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
            writer.Write(htmlDocument);
            writer.Close();

        }
    }

Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.

Leave a Reply