YOUR FEEDBACK
Optimizing Database Performance in J2EE Applications
kasiazaki wrote: dfdf

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Google Maps and ASP.NET
Building a custom server control

Digg This!

Page 2 of 2   « previous page

Overlaying Markers and Pop-Up Windows
Another cool feature of Google Maps is the ability to display markers on the map and attach pop-up windows to these markers on the click event. It is possible to display formatted HTML containing links and images in these pop-up windows. Let us see how to do the same using the GMap ASP.NET control. Let's take the previous example and modify it to add two markers. One would be a plain marker and the other would have a pop-up window that would display some text. The GMap ASP.NET control has an overloaded method called OverlayMarker that takes the formatted HTML as a string parameter. If the overloaded method is called and some HTML is passed to the method, a click event is automatically passed to the marker and the info window is displayed. Listing 4 shows the code to overlay two markers and Figure 4 shows the output of the same.

Overlaying Custom Markers
Google gives us the flexibility to replace their standard marker icon with any custom icon that we specify. The same functionality is provided by the GMap ASP.NET control. In order to do so, we need to define a GIcon class with at least the following properties:

  • URL of the image that would represent the GIcon
  • URL of the shadow image
  • Size of the image
  • Size of the shadow
  • The point at which the icon is to be anchored to the icon
In case info windows are used, it is also necessary to specify the point where the info window is to be anchored to the map. For this example we will be borrowing the icons from the Google Ride Finder application. Let's take the same two points that we used in the marker example and replace the standard marker icons with these custom icons. The code in Listing 5 is same as that of Listing 4, except for the use of custom icons. Figure 5 shows the output.

Overlaying Lines
In this section we will see how to overlay a line on a Google Map. Lines can be overlaid on maps to denote routes, boundaries, or some other specific purpose a developer may deem necessary. As in the Google Maps API, the GMap ASP.NET control also allows overlay of lines. In the GMap control, the GLine class represents a line and takes a collection of GPoints to plot a line through them. It is also possible to set the color, width, and opacity of the line. While the Google Maps API requires color to be passed in as a Hex value, the GMap control takes in a System.Drawing.Color structure, thereby making it easier to set the color by name. Listing 6 shows the code and Figure 6 shows the rendering.

Using Multiple Google Map Controls in a Page
So far in all of the examples, we have dealt with one instance of the control in a page. It is possible to have any number of GMap controls in a single page and have granular control over each one of them. In this example, we have four instances of the control and will center and zoom them on four different cities. Listing 7 shows the code and Figure 7 shows the output in the browser. It is possible to have markers or lines on any of these controls.

Binding Data to the Control
The GMap ASP.NET control supports data binding and it is possible to bind it to any data source that implements the IEnumerable interface, hence it can bind to most of the commonly used sources such as data tables, datasets, and collections. As of now the control only supports overlaying of standard markers via data binding. The control exposes the following properties that need to be set before data binding:

  • MarkerLatitudeField: Property used to specify which field from the data source will bind to the latitude field of each marker in the control
  • MarkerLongitudeField: Property used to specify which field from the data source will bind to the longitude field of each marker in the control
  • MarkerText: Property used to specify which field from the data source will bind to the Text field of each marker in the control (this is optional)
  • DataSource: Property used to set the source of data
In this example we will first populate a table with a point and then bind it to the GMap control. Listing 8 shows the code involved in the example and Figure 8 shows the output.

Conclusion
The Google Maps API is very versatile. I hope this control will make it easier for .NET developers to harness the potential of this API.

References


Page 2 of 2   « previous page

About Jeevan Murkoth
Jeevan Murkoth is a Microsoft Certified Solutions Developer (MCSD) in .NET (Early Achiever) and a Microsoft Certified Application Developer (MCAD) in .NET. He currently consults for Tennessee Valley Authority and lives in Chattanooga, TN. He has an MS in Management Information Systems from Texas Tech University.

Noble wrote: I got the same java script error in JScriptGenerator.cs after replacing sOverLayFunction.Append(" try{this.overlays.push(a[ i]); \n"); with sOverLayFunction.Append(" try{this.addOverlay(a[i]) ; \n"); Can You Please put your full JScriptGenerator.cs
read & respond »
Sajid Mushtaq wrote: i cant find a link to download the source code and the control. Please help. Regards, Sajid
read & respond »
Shabdar wrote: I have created similar control. It works with latest versions of Google Maps API. Here is the link, http://www.shabdar.org/go ogle-maps-user-control-fo r-ASP-Net-part1.html
read & respond »
Ghata wrote: This one works with GMAP2 http://www.shabdar.org/go ogle-maps-user-control-fo r-ASP-Net-part1.html
read & respond »
Balvinder wrote: I have downloaded GMap control and sample applications. But OverlayMarker and OverlayLine does not work. Following code does not works. Please, tellme what is going wrong ? Suggest any modifications in code. GMapControl1.Width=400; GMapControl1.Height=400; GMapControl1.MapType=MapC ontrol.GMapType.MAP; GMap Control1.ScrollControlTyp e=MapControl.GMapScrollCo ntrol.LARGE ; GMapControl1.ShowMapTypeC ontrol=true; GMapControl1 .GoogleMapKey=Configurati onSettings.AppSettings["D evKey"]; GPoint myPoint= new GPoint(36.1645,-86.7811); GPoint myPoint2= new GPoi nt(36.224264,-85.928273); string sFormattedHtml="Na shville<img src=D:\\Ma pPoint\\SourceCode_Murkot h0401\\SourceCode\\Sample Solution\\images\\image.g if /><a href= >Visit Nashville "; // string sFormattedHtml = "hello"; GMarker myMarker= new GMarker(myPoint); G...
read & respond »
Sai wrote: There is a change in google api and this shows a javascript error. So please remove "this.reOrderOverlays();" from GenerateNewOverLayFu nction() in JScriptGenerator.cs file. You may find more info on this at http://groups.goo gle.com/group/Google-Maps -API/browse_thread/thread /96fe322280299e0b
read & respond »
baybay wrote: This article is horrible. Very generic. Don't waste your time.
read & respond »
fabrice wrote: How do you deal with events ? like moveend or dragend ? Cheers
read & respond »
Derek wrote: Here's the fix for the marker issue that everyone seems to still be having a problem with. In JScriptGenerator.cs replace sOverLayFunction. Append("try{this.overlays .push(a[i]); \n"); with sOverLayFunction.Append(" try{this.addOverlay(a[i]) ; \n"); the overlays.push is what looks to be causing the problem. After making this fix, I can lay markers on the map. Cheers
read & respond »
Josh wrote: Patrick - Here is good easy to use control with full functionality. I did have a problem in deployment with the key, so I would recommend testing it on your server before you do a lot of development.
read & respond »
Patrick wrote: Hi Jeevan, What an excellent tutorial and powerful tool. I spent many hours trying to find where the fix for the markers and line overlays might be, but (like everyone who has filled out 4 pages of feedback pleading for help with this) I was unable. I am not so great with Javascript, but read the rest of your code with great interest. I have looked far and wide for a similar tool, and although several exist they either use a newer version of .net from me or have some such other problem. Yours works beautifully except for the known issues. What are we, the less than Code Grand Wizards, to do in order to convince Jeevan to rework the tool. Could we put a PayPal donation box on the site and bribe you to do it? Could we set the code up as a project on sourceforge.net and try to rework it that way? Coul...
read & respond »
Jeevan wrote: Hi Josh, The control when written in 2005 was made to work with Google maps Beta 1. The current version is version 2. I assume that google has made some changes to the way markers are being displayed, hence some of you are having issues in getting them to display. I haven't had a chance to update the control for the new version.Since the source code is available, I'd encourage you to take a look at it. Thanks
read & respond »
Josh wrote: Great, but I kind of need to display markers. Its actually the key part of displaying the map. After playing around with this a while, markers or custom markers will not display. Several others had the same problem. Any ideas, or just skirting the issue?
read & respond »
Eric wrote: Where do I go to download the GMap Control. I was lost trying to follow the step.
read & respond »
san wrote: I have downloaded GMap control and sample applications. But OverlayMarker and OverlayLine does not work. Following code does not works. Please, tellme what is going wrong ? Suggest any modifications in code. GMapControl1.Width=400; GMapControl1.Height=40 0; GMapControl1.MapTyp e=MapControl.GMapType.MAP ; GMapControl1.ScrollC ontrolType=MapControl.GMa pScrollControl.LARGE ; GMapControl1.ShowMapTy peControl=true; GMapCo ntrol1.GoogleMapKey=Confi gurationSettings.AppSetti ngs["DevKey"]; GPoint myPoint= new GPoint(36.1645,-86.7811); GPoint myPoint2= new G Point(36.224264,-85.92827 3); string sFormattedH tml="Nashville<img src =D:\\MapPoint\\SourceCode _Murkoth0401\\SourceCode\ \SampleSolution\\images\\ image.gif /><a href= >Visit Nashville "; // string sFormattedHtml = "hello"; ...
read & respond »
Priya wrote: I am getting an error in reOrderOverlays(). It says object dosen't support this property. I am getting a java script error. Is there a fix for this? Please let me know.
read & respond »
Rhys wrote: This looks awfully plaguerised from an article at another site... http://www.codepr oject.com/aspnet/LatLaysF lat-Part1.asp Naughty, naughty, very naughty!
read & respond »
Troy Johnson wrote: Anyone know if this is or will soon be updated to use GMap2?
read & respond »
Niketa wrote: this code is working fine but i am not able to draw lines and could not use marker. please help me in this. i had to commen reOrderOverlays() funstion call as my code was not working . please suggest me how can i resolve this. Thanks a lot.
read & respond »
Ridhi wrote: Thanks Jeevan , but i am not able to see marker and polylines or lines using this tool , please help me in this . i have tried simple code . i had to comment reOrderOverlays() to make this tool working. Please suggest the way to resolve it or problem.
read & respond »
MICROSOFT .NET LATEST STORIES
"Cloud Computing Is the Plan" - Ballmer Memo
With Microsoft mandarin Kevin Johnson bolting to Jupiter, leaving Microsoft to lick its wounds over Yahoo and reorganize, CEO Steve Ballmer sent out an all-hands e-mail to Microsoft folk encapsulating the message he delivered to financial analysts gathering in Redmond Thursday. Ballmer
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
Virtualization, Microsoft, Yahoo & Google
Citrix has tapped its VP of channels and emerging product sales Al Monserrat to replace its departing sales chief John Burris, who, as previously reported, is going to Sourcefire as CEO. A couple of years ago Monserrat was responsible for Citrix' North American sales. Meanwhile, Citrix
AJAX RIA Tutorial - Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight
In ASP.NET 2.0, we introduced a very powerful set of application services in ASP.NET (Membership, Roles and profile). In 3.5 we created a client library for accessing them from Ajax and .NET Clients and exposed them via WCF web services. For more information on the base level ASP.NET
Cloud Computing - IBM's Got Its Head in the Clouds
Reminding people of how its backing was the making of Linux, IBM, to no one's surprise, has thrown its support behind cloud computing, that delicious nexus of every chi-chi buzzword technology currently in vogue: Web 2.0, rich Internet applications, software-as-a-service, SOA, grid com
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Anexeon Achieves Microsoft Gold Partner Certification
Anexeon, LLC announced today it has achieved Microsoft Gold Certified Partner status along wit