Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Hopefully anyone can help me with this,
I want to show google maps in my app using a
webbrowser control, but the problem is not
getting it to show the maps.

I only want it to show the maps not the whole
google maps webpage.

I want to hook up text boxes to the city name
and addr..

This is what I've tried:

private void Loadmaps()
       {
           DataTable dt = new DataTable;
           Addr = txtPhyAddLine1.Text;
           City = txtPhyCity.Text;

           try
           {
               for (int i = 0; i < dt.Rows.Count; i++)
               {
               StringBuilder OpenUpdate = new StringBuilder();
               OpenUpdate.Append("http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false");

               mapbrowser.Navigate(OpenUpdate.ToString());
               }
           }

           catch (Exception ex)
           {
               MessageBox.Show(ex.Message.ToString(), "Unable To Load Web Browser");
           }
       }


PLEASE ANY HELP WOULD BE APPRICIATED!!
Posted
Updated 2-Aug-11 13:16pm
v2
Comments
Dr.Walt Fair, PE 2-Aug-11 19:16pm    
Fixed code formatting.

Have a look at GMap.NET[^]
 
Share this answer
 
You are doing it wrong. What you have done is, the stringbuilder is appending the same text over and over again with each increment in for loop. I have fixed the code for you. Note: use of stringbuilder is not required.
C#
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (Char)Keys.Enter)
    {
      City = txtPhyCity.Text;
      string openupdate = "http://maps.googleapis.com/maps/api/staticmap?center="+City+"&zoom=14&size=400x400&sensor=false";

      mapbrowser.Navigate(OpenUpdate);
    }
}
 
Share this answer
 
HI
Try this code, this one works for me......

C#
StringBuilder queryAddress = new StringBuilder();

queryAddress.Append("http://maps.googleapis.com/maps/api/staticmap?center="+City+"&zoom=14&size=400x400&sensor=false");

webBrowser1.Navigate(queryAddress.ToString());
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900