SIGN UP MEMBER LOGIN:    
ARTICLE

Displaying Google Maps in ASP.NET Web Application

Posted by Prashanth Chindam Articles | ASP.NET Programming January 02, 2011
To develop a web application using asp.net for displaying GoogleMaps.
Reader Level:
Download Files:
 

Objective:

To develop a web application using asp.net for displaying GoogleMaps.

Steps:

1. Download 'GMaps.dll' file, extract the folder.

2. Open VisualStudio.Net -> File -> New Web Site

3. Go to Tool Box -> right click on any tab -> Add New Tab

  • Name it as GoogleMapControls -> right click on 'GoogleMapControls' tab
  • Browse.. 'GMaps.dll' (GMaps.dll file is provided in gmaps.zip along with the source code)
  • OK.

Now, GMaps controls will appear under 'GoogleMapControls' tab.

4. Design:

Gmap1.gif

Design the form as above with 5 TextBoxes, 1 Button and 1 GMap control (present under 'GoogleMapControls' tab).

5. Code:

using System;
using System.Configuration;
using Subgurim.Controles;
public
partial class _Default : System.Web.UI.Page
{
    protected void btnShowMap_Click(object sender, EventArgs e)
    {
        string fulladdress = string.Format("{0}.{1}.{2}", TextBox1.Text, txtCity.Text, txtCountry.Text);
        string skey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];
        GeoCode geocode;
        geocode = GMap1.getGeoCodeRequest(fulladdress);
        var glatlng=new Subgurim.Controles.GLatLng(geocode.Placemark.coordinates.lat,geocode.Placemark.coordinates.lng);
        GMap1.setCenter(glatlng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
        var oMarker=new Subgurim.Controles.GMarker(glatlng);
        GMap1.addGMarker(oMarker);   
    }
}

6. web.config file code:
Inorder to use the Gmaps controls, write the following code under appSettings of web.config file:

 <appSettings>
    <
add key="googlemaps.Subgurim.net" value="YourGoogleMapsAPIKeyHere="/>
  </appSettings
>

Output:

Gmap2.gif

Note:

'GMaps.dll'is provided in 'gmaps.zip' along with the source code.

erver'>
Login to add your contents and source code to this article
share this article :
post comment
 

Man, how can I get this Lat and Long through database, in C# - asp.net Tks, Rodrigo (Brazil)

Posted by Rodrigo galhardo Feb 16, 2012

Hi..i've implement all source code above in my web site with asp.net.. but when i change the country into Indonesia and I press the button, the location showed in maps still the same and nver be changed.. Could you help me ?

Posted by alfius samuel Jan 10, 2012

Thanks

Posted by krishna kumar Dec 13, 2011

I have added the dll to the tab and after dragging the control on the form and running the page "UNrecognized configuration section appSettings" is appeared please help. <appSettings> <add key="googlemaps.Subgurim.net" value="ABQIAAAAQMrMRLn5-ACl9oqPVJ21sRQmhWQ5KBV6MkZXLVJiPmadlt4-qxQ7X4CfEizeNKmaYPb8tpe2xEaJYg"/> </appSettings> This is the appsettings section used in my application

Posted by venugopal neeli Mar 31, 2011

Awesome, thanks MR. but what if i wanted to select a location on the map then automatically display its longitude and latitude on a textbox?

Posted by rirhandzu mhlarhi Feb 18, 2011
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor