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

I created a form viewing google maps fine, but
the problem is it is showing the whole google maps webpage now.
I only want it to view the map , can anyone help me
out with this please.

Any suggestion would be appriciated..

[Update-added OP's code as per comment]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapAddress
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnMapAddress_Click(object sender, EventArgs e)
        {
            try
            {
                string street = string.Empty;
                string city = string.Empty;
                string state = string.Empty;
                string zip = string.Empty;

                StringBuilder queryAddress = new StringBuilder();
                queryAddress.Append("http://maps.google.com/maps?q=");

                if (txtStreet.Text != string.Empty)
                {
                    street = txtStreet.Text.Replace(' ', '+');
                    queryAddress.Append(street + ',' + '+');
                }

                if (txtCity.Text != string.Empty)
                {
                    city = txtCity.Text.Replace(' ', '+');
                    queryAddress.Append(city + ',' + '+');
                }

                if (txtState.Text != string.Empty)
                {
                    state = txtState.Text.Replace(' ', '+');
                    queryAddress.Append(state + ',' + '+');
                }

                if (txtZipCode.Text != string.Empty)
                {
                    zip = txtZipCode.Text.ToString();
                    queryAddress.Append(zip);
                }

                webBrowser1.Navigate(queryAddress.ToString());

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Unable to Retrieve Map");
            }
        }
    }
}
Posted
Updated 18-Jul-11 12:16pm
v2
Comments
Salmen Essridi 18-Jul-11 17:20pm    
Can you show us some code ?
Ben Paxton 18-Jul-11 17:44pm    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapAddress
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnMapAddress_Click(object sender, EventArgs e)
{
try
{
string street = string.Empty;
string city = string.Empty;
string state = string.Empty;
string zip = string.Empty;

StringBuilder queryAddress = new StringBuilder();
queryAddress.Append("http://maps.google.com/maps?q=");

if (txtStreet.Text != string.Empty)
{
street = txtStreet.Text.Replace(' ', '+');
queryAddress.Append(street + ',' + '+');
}

if (txtCity.Text != string.Empty)
{
city = txtCity.Text.Replace(' ', '+');
queryAddress.Append(city + ',' + '+');
}

if (txtState.Text != string.Empty)
{
state = txtState.Text.Replace(' ', '+');
queryAddress.Append(state + ',' + '+');
}

if (txtZipCode.Text != string.Empty)
{
zip = txtZipCode.Text.ToString();
queryAddress.Append(zip);
}

webBrowser1.Navigate(queryAddress.ToString());

}

catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Unable to Retrieve Map");
}
}
}
}
Ben Paxton 18-Jul-11 17:45pm    
Please any help would be appriciated

1 solution

You might be able to use that depending of your application. There is a limit on the number of request that can be made per day.

Otherwise, you can uses OpenStreetMap which is free or pay for Google or Bing maps but this is quite expensive...

Google Static Maps[^]
 
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