Google Maps into an ASP.NET page

Mohammed Al-Atari
URL:http://blog.evonet.com.au/post/Integrating-Google-Maps-into-an-ASPNET-page.aspx
While Microsoft have released their new Virtual Earth ASP.NET Control, I still haven’t found a decent wrapper that converts addresses to langitude and longitude co-ordinates.  There is a Geo coder web service available here (this shows the co-ordinates for the White House) but it seems to only work for US addresses, which doesn’t help me at all.
So for the moment, I’m still using Google Maps, and have prepared the following to show you how to integrate Google Maps into your ASP.NET pages
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 /> 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″ %>
Step 4: Add code to display the mapFinally, 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 = 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
That’s it! Check out the demo or download the source code, and let me know if you find a good wrapper for the Virtual Earth ASP.NET control!

1,176 Responses to “Google Maps into an ASP.NET page”

  • Anonymous Says:

    This has definitely sparked up an idea in my mind. This really is a superb weblog submit.

  • Anonymous Says:

    Very interesting thread; I too agree with the list, though I would add a few more events to it.

  • Anonymous Says:

    Great work guys .keep up with your good work.We always look forward to your work.

  • Anonymous Says:

    Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is great blog. A great read. Ill definitely be back.

  • Anonymous Says:

    Hi! I just wanna give a huge thumbs up for the great info you have here on this post. I will be returning to your blog for more later.

  • Anonymous Says:

    I enjoyed reading & I must say that I was very impressed with your writing skills. Keep up the good work it’s very refreshing to see someone like you :)

  • Anonymous Says:

    It is good too read your website again dude, i see some interesting updates here…

  • Anonymous Says:

    I find myself coming to your blog more and more often to the point where my visits are almost daily now!

  • Anonymous Says:

    I want to start blogging too what do you think, which blog cms is good for noob?

  • Anonymous Says:

    I just added your blog site to my blogroll, I pray you’d think about doing the same.

  • Anonymous Says:

    Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed surfing around your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

  • Anonymous Says:

    Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?

  • Anonymous Says:

    this site is rattling user friendly ! .

  • Anonymous Says:

    Super-Duper website! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also

  • Anonymous Says:

    It is absolutely a pleasurable post. An writing like this reports exactly how deeply the concept is actually fully understood by source.

  • Anonymous Says:

    Can I just say what a relief to come across someone who actually knows what theyre talking about on the internet. More people need to read and understand this. I cant believe youre not more popular because you definitely have talent at this.

  • Anonymous Says:

    ALL READY THINKING FOR NEXT SEASON. DATS SAD.

  • Anonymous Says:

    I am grateful to you for this wonderful content. You truly did make my day :

  • Anonymous Says:

    I’m so glad this online factor works and your post actually helped me. Could take you up on that property advice you

  • Anonymous Says:

    Ha, that? Beyond question a Genuinely meet suggestion. Uncountable thanks so much conducive to this!

  • Anonymous Says:

    I couldn’t resist commenting – great info thanks.

  • Anonymous Says:

    I agree with your Google Maps into an ASP.NET page | Mohammed Al-Atari, wonderful post.

Leave a Reply

Only 250 Characters