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!
Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Facebook
  • Live-MSN
  • TwitThis
  • LinkedIn
  • MySpace
  • email

81 Responses to “Google Maps into an ASP.NET page”

  • Anonymous Says:

    some come with recovery disk and some companies try to charge you for them, but you can always make them yourself. And ALWAYS backup your important files to an external HDD or Flash Drive or somthing

  • Anonymous Says:

    A thoughtful insight and ideas I will use on my blog. You’ve obviously spent a lot of time on this. Thank you!

  • Anonymous Says:

    awesome post. I have discovered for myself just how flexible WP is, as a hosting platform for your website. you literally have everything you need to publish a website at your fingertips, through WordPress. thanks.

  • Anonymous Says:

    Saludos desde el frío Polo Sur :)

  • Anonymous Says:

    I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your web site to look at the latest stuff you post.

  • Anonymous Says:

    Don’t you recognize that it is the best time to get the mortgage loans, which will make you dreams real.

  • Anonymous Says:

    I know its my first post here, but ive been reading for a while and really enjoy it

  • Anonymous Says:

    Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely useful for me.

  • Anonymous Says:

    I really love going back to your site to read your story and see more pictures that are really taken with great care. . . . . .

  • Anonymous Says:

    I am really thankful to the author of this post for making this lovely and informative article live here for us. We really appreciate ur effort. Keep up the good work. . . .

  • Anonymous Says:

    awesome post. I have discovered for myself just how flexible WP is, as a hosting platform for your website. you literally have everything you need to publish a website at your fingertips, through WordPress. thanks.

  • Anonymous Says:

    Thank you so much for this valuable information. Very useful indeed. . . . .

  • Anonymous Says:

    There are certainly a lot of details like that to take into consideration. That?s a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be

  • Anonymous Says:

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. . . .

  • Anonymous Says:

    Hi Guy, this good blogs, thanks

  • Anonymous Says:

    We just couldnt leave your website before letting you know that we really enjoyed the quality information you offer to your visitors… Will be back often to check up on new posts

  • Anonymous Says:

    Great blog! I really love how it is easy on my eyes as well as the information are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your rss feed which really should do the trick! Have a nice day!

  • Anonymous Says:

    I think this web site’s format is done well.

  • Anonymous Says:

    Thanks for the sharing really usefull. I would like to bookmark this site.

  • Anonymous Says:

    Advantageously, the article is actually the greatest topic on curing acne naturally. I concur with your conclusions and will eagerly look forward to your coming updates. Saying thanks will not just be enough, for the phenomenal lucidity in your writing. I will immediately grab your rss feed to stay informed of any updates.

  • Anonymous Says:

    I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .

  • Anonymous Says:

    Its very informative and interesting article.all the points are very useful. Simple but very effective writing. Thanks for sharing such a nice post.

  • Anonymous Says:

    This is a good blog. Keep up all the work. I too love blogging and expressing my opinions. Thanks :)

  • Anonymous Says:

    This is a really good read for me. Must admit that you are one of the coolest bloggers I ever saw. Thanks for posting this informative article.

  • Anonymous Says:

    Advantageously, the post is in reality the freshest topic on curing acne naturally. I concur with your conclusions and will thirstily look forward to your upcoming updates. Just saying thanks will not just be enough, for the phenomenal clarity in your writing. I will right away grab your rss feed to stay abreast of any updates.

  • Anonymous Says:

    Easily, the post is actually the greatest on this deserving topic. I agree with your conclusions and will thirstily look forward to your coming updates. . . . .

  • Anonymous Says:

    I love reading and I am always searching for informative information like this! You are bookmarked!. . . . . .

  • Anonymous Says:

    Guys, Great article and very very interesting blog. That’s one thing I’m really looking forward. Looking forward to reading more from you next week.

  • Anonymous Says:

    I enjoy your website – great work!

  • Anonymous Says:

    Wonderful blog! I really love how it’s easy on my eyes and the information are well written. I am wondering how I can be notified whenever a new post has been made. I have subscribed to your rss feed which need to do the trick! Have a nice day!

  • Anonymous Says:

    I found your site via yahoo thanks for the post. I will save it for future reference. Thanks

Leave a Reply