How to use Gmap in Windows application.
This Resource will help you to add Gmap in your Windows application. In this application we get the location on the map by entering latitude and longitude values in respective Textboxs. You can show the obtained map in Picture box or Web Browser control. Find How to use Gmap in Windows application?
Learn how to use Gmap in Windows application?
In this Windows Application I have used Two text boxes to enter the latitude and Longitude values respectively. One button is also used.
When we enter the Values for Latitude and Longitude and on Button Click a map will be generated for that location .
You can show this map in Picture box or also in WebBrowser control of .net.
Code of Application is as shown below:
Below is the code of Button click event.
Google Map in Picture Box:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty || textBox2.Text == string.Empty)
{
MessageBox.Show("Please enter latitude and longitude value", "Missing Value");
return;
}
try
{
WebClient client = new WebClient();
var requestUrl = string.Format("http://maps.googleapis.com/maps/api/staticmap?center=" + textBox1.Text + "," + textBox2.Text + "&maptype=satellite&zoom=12&size=500x500&sensor=true");
byte[] result = client.DownloadData(requestUrl);
MemoryStream ms = new MemoryStream(result);
Image returnImage = Image.FromStream(ms);
pictureBox1.Image = returnImage;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
}
here values of Latitude and longitude are passed to the maps.googleapis.com using certain parameters. We will get the map and this map is shown in Picture box.
Google Map in Web Browser:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty || textBox2.Text == string.Empty)
{
MessageBox.Show("Please enter latitude and longitude value", "Missing Value");
return;
}
try
{
StringBuilder address = new StringBuilder();
address.Append("http://maps.googleapis.com/maps/api/staticmap?center=" + textBox1.Text + "," + textBox2.Text + "&maptype=satellite&zoom=12&size=500x500&sensor=true");
webBrowser1.Navigate(address.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
}
you can visit http://code.google.com/ for more information regarding parameters that i have used.
It's like you're on a mission to save me time and money!