Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 Google-Maps
How can Google Maps be used in a simple C# Windows Forms Application utilising a WebBrowser control?
 
As I understand Google Maps API v3 no longer requires a key = I won't need an external dedicated web site & key from Google.
 
The example given here (http://www.codeproject.com/KB/cs/GpsMapping.aspx) gets pretty close but is displaying the full fat google maps web site instead of a map only version (eg: http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html).
 
Am I missing an important point regarding simple API v3 integration in C# Forms applications? Confused | :confused:
Posted 23-Oct-10 1:06am
Comments
Member 10623605 at 12-Mar-14 6:45am
   
how to integrate google news with windows application?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Many thanks for your help shakil0304003. However, I already came across both articles previously in my search for a solution.
 
Unfortunately, while the 1st reference talks about a .Net CompactFramework for PDAs and is complex in it's coding, the 2nd reference leaves the same question that I've got unanswered (customised GoogleMaps through WebBrowser control in a C# WinForm application).
 
Sofar I got to (not so elegant) code versions:
private void button1_Click(object sender, EventArgs e)
{
    // UpdateGoogleMap();
    StringBuilder queryAddress = new StringBuilder();
    // Open locally stored html file in webbroswer control, not very ellegant at all
    queryAddress.Append("C:\\GMtest\\GoogleMapsV3.html");
 
    //Open Google's example code, this requires the HTML code to be hosted on a web server (not acceptable).
    queryAddress.Append("http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html");
 
    // Any other possible option? 

    this.webBrowser1.Navigate(queryAddress.ToString());
}
Option two was to directly inject html code (dirty aproach?, everything JScript wise would have to be manually inserted/coded):
<preprivate void="" eventargs="" mode="hold" />{
    object empty = System.Reflection.Missing.Value;
    axWebBrowser1.Navigate("about:blank", ref empty, ref empty, ref empty, ref empty);
    // Manuall inject HTML code instead of using a locally stored file: C:\GMtest\GoogleMapsV3.html 
    setBrowserHtml(" <h1>Hello world!</h1>");
}
Is there any elegant and simple solution to what I want to achieve?
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can see this links

Click

Click
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Below is code, I am using in a project
 
#Region "GoogleMap"
    Dim GoogleMapLocation As String = ""
    Private Sub LoadGoogleMap(ByVal Location As String)
        If GoogleMapLocation = Location Then Exit Sub
        GoogleMapLocation = Location
        Dim a As String = "" & vbCrLf & _
    " <html>  " & vbCrLf & _
    " <head> " & vbCrLf & _
    " <meta name=""viewport"" content=""initial-scale=1.0, user-scalable=no"" /> " & vbCrLf & _
    "  " & vbCrLf & _
    " <script type=""text/javascript"" src=""http://maps.google.com.mx/maps/api/js?sensor=true&language="en"""></script> " & vbCrLf & _
    " <script type=""text/javascript""> " & vbCrLf & _
    "  " & vbCrLf & _
    " var geocoder; " & vbCrLf & _
    " var map; " & vbCrLf & _
    "  " & vbCrLf & _
    "  " & vbCrLf & _
    " function initialize(address) { " & vbCrLf & _
    "  " & vbCrLf & _
        " geocoder = new google.maps.Geocoder();  " & vbCrLf & _
    "  " & vbCrLf & _
        "         var myOptions = {zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP}  " & vbCrLf & _
    "  " & vbCrLf & _
        " geocoder.geocode({ 'address': (address ? address : """ & Location & """)}, function (results, status) { " & vbCrLf & _
            " if (status == google.maps.GeocoderStatus.OK) { " & vbCrLf & _
                " map.setCenter(results[0].geometry.location); " & vbCrLf & _
                " var marker = new google.maps.Marker({ " & vbCrLf & _
                    " map: map, " & vbCrLf & _
                    " position: results[0].geometry.location " & vbCrLf & _
                " }); " & vbCrLf & _
            " } else { " & vbCrLf & _
                "  " & vbCrLf & _
            " } " & vbCrLf & _
        " }); " & vbCrLf & _
    "  " & vbCrLf & _
        " map = new google.maps.Map(document.getElementById(""map_canvas""), myOptions); " & vbCrLf & _
    " } " & vbCrLf & _
    "  " & vbCrLf & _
    "  " & vbCrLf & _
    " </script> " & vbCrLf & _
    " </head> " & vbCrLf & _
    " <body onload=""initialize()""> " & vbCrLf & _
    "     <div id="" map_canvas="" style=""></div> " & vbCrLf & _
    "  " & vbCrLf & _
    "   </body> " & vbCrLf & _
    " </html> "
        DisplayHtml(a)
    End Sub
 
    Private Sub DisplayHtml(ByVal html As String)
        WebBrowser1.Navigate("about:blank")
        If WebBrowser1.Document IsNot Nothing Then
            WebBrowser1.Document.Write(String.Empty)
        End If
        WebBrowser1.DocumentText = html
    End Sub
#End Region
 
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 30 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100