Google Maps into an ASP.NET page
Mohammed Al-Atari
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!
April 1st, 2011 at 2:55 PM
This has definitely sparked up an idea in my mind. This really is a superb weblog submit.
April 2nd, 2011 at 7:09 AM
Very interesting thread; I too agree with the list, though I would add a few more events to it.
April 2nd, 2011 at 7:58 AM
Great work guys .keep up with your good work.We always look forward to your work.
April 2nd, 2011 at 5:42 PM
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.
April 2nd, 2011 at 10:47 PM
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.
April 3rd, 2011 at 11:41 AM
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
April 3rd, 2011 at 11:15 PM
It is good too read your website again dude, i see some interesting updates here…
April 4th, 2011 at 12:57 PM
I find myself coming to your blog more and more often to the point where my visits are almost daily now!
April 4th, 2011 at 2:22 PM
I want to start blogging too what do you think, which blog cms is good for noob?
April 4th, 2011 at 3:47 PM
I just added your blog site to my blogroll, I pray you’d think about doing the same.
April 4th, 2011 at 5:37 PM
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!
April 4th, 2011 at 9:57 PM
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?
April 4th, 2011 at 10:13 PM
you can use my msn or email which exits in right panel
April 5th, 2011 at 12:40 AM
this site is rattling user friendly ! .
April 5th, 2011 at 9:58 AM
Super-Duper website! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also
April 5th, 2011 at 12:23 PM
It is absolutely a pleasurable post. An writing like this reports exactly how deeply the concept is actually fully understood by source.
April 5th, 2011 at 4:02 PM
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.
April 5th, 2011 at 8:47 PM
ALL READY THINKING FOR NEXT SEASON. DATS SAD.
April 7th, 2011 at 3:16 PM
I am grateful to you for this wonderful content. You truly did make my day :
April 8th, 2011 at 11:35 AM
I’m so glad this online factor works and your post actually helped me. Could take you up on that property advice you
May 13th, 2011 at 9:56 PM
Ha, that? Beyond question a Genuinely meet suggestion. Uncountable thanks so much conducive to this!
August 13th, 2011 at 4:29 AM
I couldn’t resist commenting – great info thanks.
August 13th, 2011 at 5:01 AM
I agree with your Google Maps into an ASP.NET page | Mohammed Al-Atari, wonderful post.