If you need to embed and display Google Maps in your .NET WPF or WinForms application, then DotNetBrowser library can help you to implement it without much effort.



DotNetBrowser is a .NET library that allows embedding a Chromium-based web browser control into a WPF or WinForms application to display web pages built with HTML5, CSS3, JavaScript, AJAX etc. The Browser component that displays web pages has two rendering modes, lightweight and heavyweight. Both modes have advantages and limitations, and it’s up to you which one to choose.



In order to embed and display Google Maps in your .NET application you just need to create an instance of the BrowserView, embed it into a Window or any other container and load the https://maps.google.com web page using the LoadURL() method of its Browser property. The following sample demonstrates the most straightforward way of doing this,



using DotNetBrowser; using DotNetBrowser.WinForms; using System; using System.Windows.Forms; namespace GoogleMapsSample { public partial class Form1 : Form { private BrowserView browserView; public Form1() { InitializeComponent(); browserView = new WinFormsBrowserView(); this .Controls.Add((Control)browserView.GetComponent()); browserView.Browser.LoadURL( "http://maps.google.com" ); } } }

<!DOCTYPE html > < html > < head > < meta name = "viewport" content = "initial-scale=1.0, user-scalable=no" /> < style type = "text/css" > html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map-canvas { height: 100% } </ style > < script type = "text/javascript" src = "https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=false" > </ script > < script type = "text/javascript" > var map; function initialize() { var mapOptions = { center: new google.maps.LatLng(48.209331, 16.381302), zoom: 4 }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); } google.maps.event.addDomListener(window, 'load', initialize); </ script > </ head > < body > < div id = "map-canvas" /> </ body > </ html >

private void button1_Click( object sender, EventArgs e) { if (zoomValue < MAX_ZOOM) { browserView.Browser.ExecuteJavaScript( "map.setZoom(" + ++zoomValue + ")" ); } } private void button2_Click( object sender, EventArgs e) { if (zoomValue > MIN_ZOOM) { browserView.Browser.ExecuteJavaScript( "map.setZoom(" + --zoomValue + ")" ); } }

using DotNetBrowser; using DotNetBrowser.WinForms; using System; using System.Windows.Forms; namespace GoogleMapsSample { public partial class Form1 : Form { private BrowserView browserView; private int zoomValue = 4; public static readonly int MIN_ZOOM = 0; public static readonly int MAX_ZOOM = 21; public Form1() { InitializeComponent(); browserView = new WinFormsBrowserView(); this .Controls.Add((Control)browserView.GetComponent()); browserView.Browser.LoadURL( "C://map.html" ); } private void button1_Click( object sender, EventArgs e) { if (zoomValue < MAX_ZOOM) { browserView.Browser.ExecuteJavaScript( "map.setZoom(" + ++zoomValue + ")" ); } } private void button2_Click( object sender, EventArgs e) { if (zoomValue > MIN_ZOOM) { browserView.Browser.ExecuteJavaScript( "map.setZoom(" + --zoomValue + ")" ); } } } }