Note: Advice in this article will only work for DotNetBrowser 1.
See the corresponding examples for DotNetBrowser 2 in C# and VB.NET.

The complete tutorial on embedding and displaying Google Maps in your .NET WinForms application is available on C# Corner by the following link:

This tutorial also explains how to work with Google Maps JavaScript API in DotNetBrowser.


The map.html used in this sample code is the same as described in the article above.

Imports DotNetBrowser
Imports DotNetBrowser.WinForms

Public Class Form1
    Dim browser As Browser
    Dim browserView As BrowserView

    Public Sub New()
        browser = BrowserFactory.Create(BrowserType.LIGHTWEIGHT)
        browserView = New WinFormsBrowserView(browser)
        browser.LoadURL(CurDir() & "\maps.html")
    End Sub

End Class

Adding marker during runtime (e.g. on button click)

    Private Sub AddMarker_Click(sender As Object, e As EventArgs) Handles AddMarker.Click
        Dim map = browser.ExecuteJavaScriptAndReturnValue("map")
        Dim position = browser.ExecuteJavaScriptAndReturnValue(
                              "new google.maps.LatLng(" & Lat.Text & ", "& Lng.Text &")")

        Dim marker = browser.ExecuteJavaScriptAndReturnValue("new google.maps.Marker()")

    End Sub


using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication8
    public partial class Form1 : Form
        private Browser browser;
        private BrowserView browserView;

        public Form1()
            browser = BrowserFactory.Create(BrowserType.LIGHTWEIGHT);
            browserView = new WinFormsBrowserView(browser);

        private void AddMarker_Click(object sender, EventArgs e)
            JSValue map = browser.ExecuteJavaScriptAndReturnValue("map");
            JSValue position = browser.ExecuteJavaScriptAndReturnValue(
                        "new google.maps.LatLng('Lat.Text', 'Lng.Text')");

            JSValue marker = browser.ExecuteJavaScriptAndReturnValue(
                        "new google.maps.Marker()");

                                    .Invoke((JSObject)marker, position);

                                    .Invoke((JSObject)marker, map);

Please take into account that there is a specific permission that should be granted to enable geolocation in DotNetBrowser.

This code sample demonstrates how to implement the IPermissionHandler for Geolocation:

See the corresponding example for DotNetBrowser 2 here.


Private Class GeolocationPermissionHandler
    Implements IPermissionHandler

    Public Function OnRequestPermission(request As PermissionRequest) As PermissionStatus _
        Implements IPermissionHandler.OnRequestPermission

        If (request.Type = PermissionType.GEOLOCATION) Then
            return PermissionStatus.GRANTED
        End If

        return PermissionStatus.DENIED

    End Function
End Class

browserView.Browser.PermissionHandler = new GeolocationPermissionHandler()


class GeolocationPermissionHandler : IPermissionHandler
    public PermissionStatus OnRequestPermission(PermissionRequest request)
        if(request.Type == PermissionType.GEOLOCATION)
            return PermissionStatus.GRANTED;

        return PermissionStatus.DENIED;

browserView.Browser.PermissionHandler = new GeolocationPermissionHandler();