In this article I will explain with an example, how to display Google Maps in Windows Application (Windows Forms) in C# and VB.Net.
The Google Maps with markers will be embedded in Windows Application (Windows Forms) using the WebBrowser control.
 
 
Concept
In order to display Google Maps inside Windows Application, first an HTML file is generated and in that HTML file programming is done to display Google Maps with markers.
The markers are added to Google Maps from a JavaScript Array. For more details please read my article, Google Maps API V3: Populate Google Maps from array of Markers.
Then the HTML file is added to the project as an Embedded Resource. For more details please read my article, Embed and read files in Windows Application (Windows Forms) in C# and VB.Net.
Finally the contents of the HTML file are loaded into the WebBrowser control.
 
 
HTML File
Following HTML file will be used to load and display Google Maps in the WebBrowser control.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
        var markers = [
        {
            "title": 'Aksa Beach',
            "lat": '19.1759668',
            "lng": '72.79504659999998',
            "description": 'Aksa Beach is a popular beach and a vacation spot in Aksa village at Malad, Mumbai.'
        },
        {
            "title": 'Juhu Beach',
            "lat": '19.0883595',
            "lng": '72.82652380000002',
            "description": 'Juhu Beach is one of favorite tourist attractions situated in Mumbai.'
        },
        {
            "title": 'Girgaum Beach',
            "lat": '18.9542149',
            "lng": '72.81203529999993',
            "description": 'Girgaum Beach commonly known as just Chaupati is one of the most famous public beaches in Mumbai.'
        },
        {
            "title": 'Jijamata Udyan',
            "lat": '18.979006',
            "lng": '72.83388300000001',
            "description": 'Jijamata Udyan is situated near Byculla station is famous as Mumbai (Bombay) Zoo.'
        },
        {
            "title": 'Sanjay Gandhi National Park',
            "lat": '19.2147067',
            "lng": '72.91062020000004',
            "description": 'Sanjay Gandhi National Park is a large protected area in the northern part of Mumbai city.'
        }
        ];
        window.onload = function () {
            LoadMap();
        }
        function LoadMap() {
            var mapOptions = {
                center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
                zoom: 8,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var latlngbounds = new google.maps.LatLngBounds();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
 
            for (var i = 0; i < markers.length; i++) {
                var data = markers[i]
                var myLatlng = new google.maps.LatLng(data.lat, data.lng);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title: data.title
                });
                (function (marker, data) {
                    google.maps.event.addListener(marker, "click", function (e) {
                        infoWindow.setContent("<div style = 'width:200px;min-height:40px'>" + data.description + "</div>");
                        infoWindow.open(map, marker);
                    });
                })(marker, data);
                latlngbounds.extend(marker.position);
            }
            var bounds = new google.maps.LatLngBounds();
            map.setCenter(latlngbounds.getCenter());
            map.fitBounds(latlngbounds);
        }
    </script>
    <div id="dvMap" style="width: 610px; height: 405px">
    </div>
</body>
</html>
 
 
Form Controls
The following Form consists of a WebBrowser control.
Display Google Maps in Windows Application (Windows Forms) in C# and VB.Net
 
 
Namespaces
You will need to import the following namespaces.
C#
using System.IO;
using System.Reflection;
 
VB.Net
Imports System.IO
Imports System.Reflection
 
 
Displaying Google Maps in Windows Application (Windows Forms) in C# and VB.Net
Inside the Form Load event handler, first an object of the Assembly class is created and it is assigned the reference of the executing assembly.
Then the contents of the HTML file are read using a StreamReader class object using the GetManifestResourceStream function of the Assembly class.
Finally the contents of the StreamReader are read using the ReadToEnd method and are assigned to the WebBrowser control.
C#
private void Form1_Load(object sender, EventArgs e)
{
    Assembly assembly = Assembly.GetExecutingAssembly();
    StreamReader reader = new StreamReader(assembly.GetManifestResourceStream("Google_Maps_CS.Maps.htm"));
    webBrowser1.DocumentText = reader.ReadToEnd(); 
}
 
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim assmbly As Assembly = Assembly.GetExecutingAssembly()
    Dim reader As New StreamReader(assmbly.GetManifestResourceStream("Google_Maps_VB.Maps.htm"))
    WebBrowser1.DocumentText = reader.ReadToEnd()
End Sub
 
 
Screenshot
Display Google Maps in Windows Application (Windows Forms) in C# and VB.Net
 
 
Downloads