Virtual Earth API: Adding KML or GeoRSS Layers to the Map


One of the new features of the Virtual Earth v6 Map Control API is the ability to import KML layers on the map.  Previous versions of the API allowed you to import GeoRSS using client-side XML parsing.  However, one of the restrictions was that the GeoRSS file had to be on the same domain as the application or the browser would bring up a security warning unless the feed was from a trusted site in the client browser. 


For v6, we have improved this by added a new VEDataType.ImportXML option to the ImportShapeLayerData call on VEMap.  This new call uses the same service from Live Search Maps which allows users to import KML, GeoRSS, or GPX into user collections. In the Virtual Earth API, it will import the XML into a shape layer in your application.  It also allows you to load these data files from different domains without causing a browser security warning.


Here are the steps for importing a KML, GeoRSS, or GPX file into your Virtual Earth application:



  1. Create a shape layer


var shapeLayer = new VEShapeLayer();


   2. Create a shape source specification with type VEDataType.ImportXML, the url to the XML file, and a reference to the shape layer:



var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,”http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml”, shapeLayer);


   3. Import the data into shape layer by calling ImportShapeLayerData on the map with the specification:



map.ImportShapeLayerData(shapeSpec);


Here’s a link to a simple example which imports a KML file from the Discovery Channel that shows different national parks around the United States:



Virtual Earth API – Import XML Sample



Note: you can also import XML files directly into Live Search Maps by opening a collection and then clicking on Import and entering the url.  You can also, use the following url syntax directly:



http://maps.live.com/?mapurl=[insert url here]


For example:



http://maps.live.com/?mapurl=http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml


Comments (5)

  1. A set of blog entries has been published recently. The details are on Keith Kinnan’s Weblog . They also

  2. A set of blog entries has been published recently. The details are on Keith Kinnan's Weblog . They

  3. 原文地址:3 Top Data Formats for Map Mashups: KML, GeoRSS and GeoJSON。 随着地图聚合给最终用户提供的一系列更广泛的工具和应用程序,它在完善程度和功能性两方面逐渐走向成熟。 因此,我们需要一些预定义好的方法在传统的地理空间数据和新一代的地图聚合之间交换、发布这些地理空间数据,并且使用一种对 web 友好的方式使用这些数据。 为了满足这种需求,出现了一些新的地理空间数据格式,这能够让更大范围的用户和开发者来聚合地理相关的信息。 下面是当

  4. turbotad says:

    I’m having some issues with using this KML overlay feature, as I’m trying to create a KML file from the collections feature on the public Bing Maps site, and then dynamically serve that KML file back up with some other internal database data.  

    My issue is more specifically here:

    http://blog.reevestech.net/2009/07/using-bing-maps-with-a-kml-feed-successes-failures/

    It’s just failing to parse with no error.  Any ideas?