C# .NET - how to create a google map based on the longitude and latitude

Asked By aman on 17-Dec-11 10:28 AM
hi all,

i want to create a google map in windows application using C#

but cant find any article which gives me an idea.....
so please help me....
Aman Khan
Suchit shah replied to aman on 17-Dec-11 10:47 AM

To get the Latitude and Longitude values of the point where your business is located, browse forhttp://maps.google.com/.

Enter some place of importance in your city, city name and country name (e.g. Railway Station, Saharanpur, India). You’ll see the area around your city or place which you’ve entered.

You can now move the map (up, down, left, or right) by moving your mouse with holding left mouse button. You can Zoom In or Zoom Out the map to get a better view of places around.

The purpose is to reach the point where you're located. When you are at that point, click right mouse button and choose 'What's here'. When you're done, you'll see a pair of numeric values in search text field. These are the values for Latitude and Longitude of your location.

Copy and paste these to a safe place. Don’t disconnect from the Internet or close this map, because we might need to come back to this map again 

A nice detail explanation good articles on the http://www.codeproject.com/KB/aspnet/GoogleMapsAPIWithInfoWin.aspx

dipa ahuja replied to aman on 17-Dec-11 12:11 PM

You need to do everything in an onload function, as described athttp://code.google.com/apis/maps/documentation/introduction.html#Loading_the_Maps_API . The basic idea (using version 2 of the API) is :

var coder = new GClientGeocoder();
"Addr to Geocode",
function(point) {
if (point) {
// Do something with GLatLng point                

To get the distance (in meters), do:

kalpana aparnathi replied to aman on 17-Dec-11 01:07 PM

Reena Jain replied to aman on 17-Dec-11 01:53 PM

try these steps

Step 1. Get a Google Maps API key

In order to use Google Maps on your site, you need to register for a free Google Maps API key from here: http://www.google.com/apis/maps/


Step 2. Download the SubGurim Google Maps wrapper dll

This one is the best Google Maps wrapper I have found so far http://en.googlemaps.subgurim.net/descargar.aspx.  It is a commercial product (from $10), or you can put up with the overlayed text in the free versions.

Download the gmaps.dll file and add it to your \bin directory.


Step 3. Set up your aspx page

In your aspx page, add a few text boxes to gather the address details.  You can simply use one textbox, or split the address to enable validation for suburbs, countries, etc.  I haven't included any form validation in my example.

<p style="text-align:right; margin-right:300px">
    Street Address: 
    <asp:textbox ID="txtStreetAddress" runat="server" Width="150px" /><br />
    <asp:textbox ID="txtSuburb" runat="server" Width="150px" /><br />
    <asp:textbox ID="txtCountry" runat="server" Width="150px" /><br /><br />
    <asp:Button Text="Show Map" ID="lnkShowMap" runat="server" />

You need to add your Google API key to your web.config file like so:

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

And finally, you need to register the SubGurim wrapper at the top of your page (or in your web.config if you have a number of pages that display maps):

<%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>

Step 4: Add code to display the map

Finally, add code that collates your address fields and calls the Google Maps wrapper.

Protected Sub lnkShowMap_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles lnkShowMap.Click
  Dim strFullAddress As String
  Dim sMapKey As String =
  Dim GeoCode As Subgurim.Controles.GeoCode
  ' Combine our address fields to create the full address.  The street,
  ' suburb and country should be seperated by  periods (.)
  strFullAddress = txtStreetAddress.Text & ". " & txtSuburb.Text
    & ". " & txtCountry.Text
  ' Work out the longitude and latitude
  GeoCode = GMap1.geoCodeRequest(strFullAddress, sMapKey)
  Dim gLatLng As New Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat,
  ' Display the map
  GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal)
  Dim oMarker As New Subgurim.Controles.GMarker(gLatLng)
End Sub

That's it! Check out the http://demo.evonet.com.au/GoogleMaps.aspx or download the http://demo.evonet.com.au/GoogleMaps.rar
Riley K replied to aman on 18-Dec-11 06:09 AM

GMap.NET is great and Powerful, Free, cross platform, open source .NET control. Enable use routing, geocoding, directions and maps from Coogle, Yahoo!, Bing, OpenStreetMap, ArcGIS, Pergo, SigPac, Yandex, Mapy.cz, Maps.lt, iKarte.lv, NearMap, OviMap, CloudMade in Windows Forms & Presentation, supports caching and runs on windows mobile!


  • gmap1512.png


Jitendra Faye replied to aman on 19-Dec-11 02:07 AM

You can use the http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding in the http://code.google.com/apis/maps/documentation/javascript/ to convert from your location name to a latitude and longitude. So you need some code like:

var geocoder = new google.maps.Geocoder(); var address = document.getElementById("address").value; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { // do something with the geocoded result // // results[0].geometry.location.latitude // results[0].geometry.location.longitude } });

<script type="text/javascript"

Hope this will help you.