Building a Webpart to Display a Virtual Earth Map Los Angeles CA

Discover how to build an ASP.NET webpart that will display coordinates on a Virtual Earth-created map. You can do this by using the IWebPart Interface, an HTTP handler, and the Virtual Earth API.

Local Companies

Moyea Software
92295612365
Hot building, ring street
LA, CA
Interneer Inc.
8005586832 x85
6101 W. Centinela Ave.
Culver City, CA
Cornerstone Concepts Inc
818-247-3909
600 W Broadway
Glendale, CA
Greene Computer Corporation
(818) 956-4961
200 S. Louise Street
Glendale, CA
Corticalx Inc Software Solutions & Technology
818-500-0881
425 E Colorado St
Glendale, CA
Alphatier Systems
818-409-8920
517 Griswold St
Glendale, CA
TimeTECH - Customizable Time and Attendance / Workforce Management Solutions
905-677-7009
7420 Airport Rd 203
Mississauga, CA
Hutchinson & Bloodgood, LLP
(818) 637-5000
101 N. Brand Blvd. #1600
Glendale, CA
Telsoft Solutions
818-545-8680
100 N Brand Blvd
Glendale, CA
Abraxas Technologies Inc
818-502-9100
450 N Brand Blvd
Glendale, CA

provided by: 
Originally published at Internet.com


Necessary Components and Setup

The items you will read about in this article came about as a result of some project work that I've been doing for the Indianapolis Colts. I've been helping to lead efforts to build and launch myColts.net, a social networking site for Colts fans. I got in to a discussion at the Microsoft MVP summit around the idea of a mashup, which is about using multiple online services to create a new one; that inspired me to play around with Virtual Earth.

The webpart display in the example relies on the native functionality contained within ASP.NET. For the purposes of this article, I'm not going to go in to all of the background setup that took place to get the web site set up to display webparts. Rather, I'm going to assume that the readership already has a site setup that will display a webpart. Worst case, you could just as easily toss the webpart portion and put the code in a page instead.

Microsoft Virtual Earth

Microsoft Virtual EarthTM is a set of services that can be used for mapping, location, and search functionality. It can be used for mapping and creating a visualization experience. It contains bird's eye, 3D, and other types of imagery. Microsoft uses it to power their Windows Live Local online local search and mapping tool. There is an Interactive SDK that is available along with a number of articles, forums, and blogs. I used this site to grab example code for how to display a virtual earth map, which consists of some simple JavaScript to include from http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js. You'll include the base JavaScript along with additional JavaScript to load your display.

To produce a map using Virtual Earth, you need address data to feed in to create the map. There is a geography-related RSS format that is widely accepted and can be used. In this example, you'll display a map of the location of the top groups on myColts.net. For this, I used the zip code of the group locations and got the latitude and longitudinal data from a geo-targeting data provider. Here is a data sample with a few records. Group Addresses Help Category: Computers & Internet, Members: 2136, New Members: 58 39.8512 -86.2651 ColtsDrive Category: Recreation & Sports, Members: 95, New Members: 2 39.8884 -86.3109 Tailgaters Category: Recreation & Sports, Members: 38, New Members: 1 44.8139 -93.9194

Http Handler

The data feed you will use for Virtual Earth is based on an RSS feed. To create the RSS feed within myColts.net, you use an HttpHandler. A custom HttpHandler allows you to have requests with a specific filename extennsion assigned to the custom handler. The custom extension in this case was arbitrarily set up as .geodata and registered as such in the web.config. Please refer to my prior article, "Use Custom HTTP Handlers in Your ASP.NET Applications," for more information on handlers. When you build your display control, you'll have it request a file with a .georss file extension on it, which in turn triggers the HttpHandler to dynamically build the RSS output necessary to feed Virtual Earth.

The following entry was put in the web.config to register the handler.

The following example code should give you an idea of how I went about producing the RSS feed that is required. You'll have to adjust the part of the code where I retrieve the data to match your own. You could just as easily feed the static XML to make it easy for testing purposes. In this example, I'm using a strongly typed dataset to retrieve data from the database. I then create an XML output. I could have used the native capability of SQL Server to create XML output, but decided just to use a base query for those who may not have SQL Server. Kindly replace the data retrieval with whatever data source you choose.

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml; namespace MyColts.Net.Handler { ///

/// Http Handler to provide access to geotargeting data. /// public class GeoData : IHttpHandler { /// Indicator if the handler can be /// reused. public bool IsReusable { get { return true; } } /// /// Constructor /// public GeoData() { } /// /// Process the request for the gallery image. /// /// public void ProcessRequest(HttpContext context) { // Send back a list of addresses for groups System.Text.StringBuilder rssOutput = new System.Text.StringBuilder( "Group Addresses"); try { using (TopGroupsTableAdapter gta = new TopGroupsTableAdapter()) { using (TopGroupsDataTable dt = gta.GetAddressByTop50() { double latitude = 0; double longitude = 0; foreach (TopGroupsRow groupRow in dt.Rows) { try { latitude = groupRow.fl_Latitude; longitude = groupRow.fl_Longitude; } catch { // Default to Indianapolis latitude = 39.76833; longitude = -86.15806; } // Add the group rssOutput.Append("") .Append("") .Append(groupRow.vc_Name) .Append("") .Append("") .Append("Category:") .Append(groupRow.vc_CategoryName) .Append(", Members: ") .Append(groupRow.in_MemberCnt) .Append(", New Members: ") .Append(groupRow.in_NewMemberCnt) .Append("") .Append("") .Append(latitude) .Append("") .Append("") .Append(longitude) .Append("") .Append(""); } } } rssOutput.Append(""); XmlDocument document = new XmlDocument(); document.LoadXml(""); XmlElement element = document.DocumentElement; element.InnerXml = rssOutput.ToString(); context.Response.Write(document.DocumentElement. OuterXml); } catch { System.Text.StringBuilder emptyOutput = new Systemm.Text.StringBuilder ("") .Append(" Group Addresses "); context.Response.Write(emptyOutput.ToString()); } } context.Response.ContentType = "text/xml"; } } }

Webpart Display

Building an ASP.NET webpart requires that you have webpart zones and other plumbing set up within your appliation. This is likely to be a topic of another article if enough people are interested, but for now you'll skip the background. The following sample control is a pretty basic webpart that doesn't do much more than get added to the display and render a map from the appropriate data source. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CompositeVirtualEarthMap.ascx.cs" Inherits="MyColts.Net.Composite. CompositeVirtualEarthMap" %>

Show Top 50 Groups Map 

The following code is from the codebehind file associated with the item. using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace MyColts.Net.Composite { public partial class CompositeVirtualEarthMap : System.Web.UI.UserControl, IWebPart { #region IWebPart stuff public string Title { get { return "Group and Friend Virtual Earth Mashup"; } set { } } public string Subtitle { get { return ""; } set { } } public string Description { get { return ""; } set { } } public string TitleUrl { get { return ""; } set { } } public string TitleIconImageUrl { get { return ""; } set { } } public string CatalogIconImageUrl { get { return ""; } set { } } #endregion protected void Page_Load(object sender, EventArgs e) { this.Page.ClientScript.RegisterStartupScript (typeof(CompositeVirtualEarthMap), "LoadMapStartup", "window.onload = function () { GeetMap(); }; \r\n", true); } } }

Figure 1 below shows what the end product looks like, based on the current data.



Click here for a larger image.

Figure 1: Webpart Display with Map

Summary

This month's column covered how to build a webpart to display a map produced from Microsoft Virtual Earth. It used an HttpHandler to produce the RSS feed format to drive Virtual Earth. It can appear daunting at first, but hopefully, as you've seen, it is pretty straightforward when you break down the individual parts of the solution.

Future Columns

The topic of the next column is yet to be determined. If you have something in particular that you would like to see explained here, you could reach me at mstrawmyer@crowechizek.com.

About the Author

Mark Strawmyer, MCSD, MCSE, MCDBA is a Senior Architect of .NET applications for large and mid-size organizations. Mark is a technology leader with Crowe Chizek in Indianapolis, Indiana. He specializes in the architecture, design, and development of Microsoft-based solutions. Mark was honored to be named a Microsoft MVP for application development with C# for the fourth year in a row. You can reach Mark at mstrawmyer@crowechizek.com.

Author: Mark Strawmyer

Read article at Internet.com site

Featured Local Company

Moyea Software

92295612365
Hot building, ring street
LA, CA

Related Local Events
Automation Technology Expo West (ATX West)
Dates: 2/9/2010 - 2/11/2010
Location: Anaheim Convention Center
Anaheim, CA
View Details

SOLAR POWER - Exhibition and Conference
Dates: 10/12/2010 - 10/14/2010
Location: Los Angeles Convention & Exhibition Center
Los Angeles, CA
View Details

REAL-TIME & EMBEDDED COMPUTING CONFERENCE - LONG BEACH 2009
Dates: 10/1/2009 - 10/1/2009
Location: Marriott Long Beach
Long Beach, CA
View Details

2009 IEEE Petroleum and Chemical Industry Technical Conference (PCIC 2009)
Dates: 9/14/2009 - 9/16/2009
Location:
Anaheim, CA
View Details

Medical Design & Manufacturing - Trade
Dates: 6/9/2009 - 6/11/2009
Location: CANON COMMUNICATIONS LLC
Los Angeles, CA
View Details