Comments
Goowee007 wrote: What is the PowerBuilder decompiler tool? I'm trying to find a PowerBuilder decompiler tool that can get the source code from .pbd or .exe.
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..

SYS-CON.TV
Today's Top SOA Links


Google Maps and ASP.NET
Building a custom server control

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

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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 6

Am I blind or they have removed the code download. I don't see how you can get it.

Is anyone else developing this control forwards? Can I update the control and republish it? (with credits obviously).

e.g. I've just spent a couple of hours updating bits to GMap2 so as to use GLatLngBounds - http://slodge.blogspot.com/2009/01/adding-bounding-box-to-google-maps-in...

Where is the control? Very unfriendly site. On 'Your Feedback' what's the point of have 'read more & respond' link if it does nothing. Really stupid.

Zachary - if you click on any of the code sample page links then there are additional download options at the top of the code sample pages - the sample code download includes the control.

One word of warning - the zip file contains lots of Apple Mac (Vista unfriendly) thumbnail files.

Thanks for this excellent article and control.

I've put the code for a fixed JScriptGenerator.cs on my blog at http://slodge.blogspot.com/2008/12/jscriptgeneratorcs-with-fixes-for.html - this fixes the addOverlays problems and the GMAP_TYPE problems.

where is the gmap control.so i can download it

I downloaded and tried to run the SampleSolution through Visual Studio. Every time that I am running the pages (.aspx) which exist in the SampleSolution I am getting the same errror 'G_MAP_TYPE' is undefined. Can someone suggest a possible solution?

asdsdfv fdfd

How to use onmouseover on marker with c# code, by default when u click on marker then info window open, i want this with onmouseover?????????

help

any one please help regarding this?

How to use onmouseover on marker with c# code, by default when u click on marker then info window open, i want this with onmouseover?????????

ah just found the source, you need to click on list 1 from the main article and then click on the first link in this page. easy when you know where to look.

where can I download this marvelous Google Maps ASP.NET Control (GMAP Control) from ? I cant seem to find a link for this anywhere. Thanks for your help and for writing this excellent article.

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


Feedback Pages:


Your Feedback
Stuart Lodge wrote: Is anyone else developing this control forwards? Can I update the control and republish it? (with credits obviously). e.g. I've just spent a couple of hours updating bits to GMap2 so as to use GLatLngBounds - http://slodge.blogspot.com/2009/01/adding-bounding-box-to-google-maps-in...
Punk wrote: Where is the control? Very unfriendly site. On 'Your Feedback' what's the point of have 'read more & respond' link if it does nothing. Really stupid.
Stuart Lodge wrote: Zachary - if you click on any of the code sample page links then there are additional download options at the top of the code sample pages - the sample code download includes the control. One word of warning - the zip file contains lots of Apple Mac (Vista unfriendly) thumbnail files.
Stuart Lodge wrote: Thanks for this excellent article and control. I've put the code for a fixed JScriptGenerator.cs on my blog at http://slodge.blogspot.com/2008/12/jscriptgeneratorcs-with-fixes-for.html - this fixes the addOverlays problems and the GMAP_TYPE problems.
Zachary Wheeler wrote: where is the gmap control.so i can download it
Evripidis wrote: I downloaded and tried to run the SampleSolution through Visual Studio. Every time that I am running the pages (.aspx) which exist in the SampleSolution I am getting the same errror 'G_MAP_TYPE' is undefined. Can someone suggest a possible solution?
sahil wrote: asdsdfv fdfd
sahil wrote: How to use onmouseover on marker with c# code, by default when u click on marker then info window open, i want this with onmouseover?????????
sahil wrote: help
sahil wrote: any one please help regarding this?
sahil wrote: How to use onmouseover on marker with c# code, by default when u click on marker then info window open, i want this with onmouseover?????????
sar wrote: ah just found the source, you need to click on list 1 from the main article and then click on the first link in this page. easy when you know where to look.
sar wrote: where can I download this marvelous Google Maps ASP.NET Control (GMAP Control) from ? I cant seem to find a link for this anywhere. Thanks for your help and for writing this excellent article.
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
Sajid Mushtaq wrote: i cant find a link to download the source code and the control. Please help. Regards, Sajid
Shabdar wrote: I have created similar control. It works with latest versions of Google Maps API. Here is the link, http://www.shabdar.org/google-maps-user-control-for-ASP-Net-part1.html
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=MapControl.GMapType.MAP; GMapControl1.ScrollControlType=MapControl.GMapScrollControl.LARGE ; GMapControl1.ShowMapTypeControl=true; GMapControl1.GoogleMapKey=ConfigurationSettings.AppSettings["DevKey"]; GPoint myPoint= new GPoint(36.1645,-86.7811); GPoint myPoint2= new GPoint(36.224264,-85.928273); string sFormattedHtml="Nashville<img src=D:\\MapPoint\\SourceCode_Murkoth0401\\SourceCode\\SampleSolution\\images\\image.gif /><a href= >Visit Nashville "; // string sFormattedHtml = "hello"; GMarker myMarker= new GMarker(myPoint); GMarker myMarker2= new GMarker(myPoint2); GMapControl1.O...
Sai wrote: There is a change in google api and this shows a javascript error. So please remove "this.reOrderOverlays();" from GenerateNewOverLayFunction() in JScriptGenerator.cs file. You may find more info on this at http://groups.google.com/group/Google-Maps-API/browse_thread/thread/96fe...
baybay wrote: This article is horrible. Very generic. Don't waste your time.
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