August 8, 2011 08:16 by
Scott
This tutorial will describe how to integrate google maps to ASP.NET page.
1. Register Google Maps API key
You can download it from here http://www.google.com/apis/maps/
2. Download the SubGurim Google Maps wrapper dll
Then, you need to download google maps wrapper at http://en.googlemaps.subgurim.net/descargar.aspx.
3. Set up your aspx page
This is for the example:
<p style="text-align:right; margin-right:300px">
Street Address:
<asp:textbox ID="txtStreetAddress" runat="server" Width="150px" /><br />
Suburb:
<asp:textbox ID="txtSuburb" runat="server" Width="150px" /><br />
Country:
<asp:textbox ID="txtCountry" runat="server" Width="150px" /><br /><br />
<asp:Button Text="Show Map" ID="lnkShowMap" runat="server" />
</p>
You need to add your Google API key to your web.config file like so:
<appSettings>
<add key="googlemaps.subgurim.net" value="YourGoogleMapsAPIKeyHere" />
</appSettings>
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" %>
4. Add code to display the map
Protected Sub lnkShowMap_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles lnkShowMap.Click
Dim strFullAddress As String
Dim sMapKey As String =
ConfigurationManager.AppSettings("googlemaps.subgurim.net")
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,
GeoCode.Placemark.coordinates.lng)
' Display the map
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal)
Dim oMarker As New Subgurim.Controles.GMarker(gLatLng)
GMap1.addGMarker(oMarker)
End Sub
Done. Great JOB.