Drive More Search Traffic to Your Maps API Site by Including KML Files in a Sitemap——Google 地图 API 文档之五

Drive More Search Traffic to Your Maps API Site by Including KML Files in a Sitemap

The Google Maps API allows you to create great maps mashups, but how can you ensure that web searchers are able to find your mashup site? Including KML files in a sitemap.xml file (see http://www.sitemaps.org/protocol.html) allows you to provide information to Google about the geolocated data in your mashup; we'll crawl the KML files you specify in the sitemap and direct users to your site when they search for matching content. As an added bonus, since KML is a standard format, users will be able to view your content within Google Earth.

Publishing a KML Sitemap involves a few easy steps:

  • Identify those features on your maps site which can be displayed as KML features.
  • Convert those features into KML equivalents and publish them within one or more KML files.
  • Create a sitemap.xml file that identifies links to all of your KML files.
  • Place the sitemap.xml in the root directory of your site.

Step 1 - Create Your KML Files

KML is Google Earth's file format for modelling and storing geographic data. The KML Tutorial highlights some of the exciting things that you can do using KML. It's up to you to decide how fancy to make the KML sitemap version of your Maps API site.

For a simple sitemap, your KML should contain a <Placemark> KML tag for each GMarker object within your Google Maps API code. For example, text that was in your GMarker objects' GInfoWindows can be placed in the <name> and/or <description> tags inside <Placemark> tags in KML. Note: KML's <description> tag supports HTML; you are encouraged to place links back to your original Maps API site here.

For example, let's say that you have a Maps API site that shows Stonehenge, England on the map.

  var map = new GMap2(document.getElementById("map"));
  map
.addControl(new GSmallMapControl());
  map
.addControl(new GMapTypeControl());
  map
.setCenter(new GLatLng(51.179045, -1.826752), 14);

 
var point = new GLatLng(51.17904, -1.826752);
 
var marker = new GMarker(point);
 
GEvent.addListener(marker, "click", function() {
   
var content = "<h1>Stonehenge, England</h1><p>Stonehenge was built around 2500B</p>";
    content
+= "<a href='http://www.example.com?view=abc&state=123'>Link to Maps API Version</a>";
    marker
.openInfoWindowHtml(content);
 
});
  map
.addOverlay(marker);

Your KML sitemap should contain a corresponding <Placemark>, such as:

  <?xml version="1.0" encoding="UTF-8"?>
 
<kml xmlns="http://earth.google.com/kml/2.1">
   
<Placemark>
     
<name>Stonehenge, England</name>
     
<description>Stonehenge was built around 2500BC</description>
     
<Point>
       
<coordinates>-1.826752,51.179045,0 </coordinates>
     
</Point>
   
</Placemark>
 
</kml>

Note that the order of the latitude and longitude values is reversed between GLatLng and the <coordinates> tag.

A more advanced KML integration could contain state variables to tell your Maps API site to show the appropriate GMarker and open its GInfoWindow. (The ones that correspond to the <Placemark> that contained the link)

Step 2 - Getting Your KML Files Indexed

Google will look for links to your KML files in your sitemap.xml as defined by the Sitemaps XML format. You can then submit this URL to Google so that it can be properly indexed. Place your sitemap.xml file in the root of your API Key directory and then submit the URL of this sitemap to Google at http://www.google.com/addurl/.

The following example shows a Sitemap with a link to a KML file.

  <?xml version="1.0" encoding="UTF-8"?>
 
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   
<url>      
     
<loc>http://www.example.com/example.kml</loc>
   
</url>
 
</urlset>

If you have a lot of data, you can create multiple KML files. Just link to all of your KML files in your sitemap.xml file via <url> tags.

  <?xml version="1.0" encoding="UTF-8"?>
 
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   
<url>      
     
<loc>http://www.example.com/example1.kml</loc>
   
</url>
   
<url>
     
<loc>http://www.example.com/example2.kml</loc>
   
</url>
   
<url>
     
<loc>http://www.example.com/example3.kml</loc>
   
</url>
 
</urlset>

Note that the Sitemap Protocol specifies that each Sitemap file must have no more than 50,000 URLs and must be no larger than 10MB (10,485,760 bytes). If you want to list more than 50,000 URLs to KML files, then you must create multiple Sitemap files. Please see the Sitemap Protocol for more details.



Helpful Tips

Use the Region-Based Network Link Feature of KML to Organize Large Sets of Data

If your Maps API Site is populated by a large database of geographic data, then using the Region-Based Network Link feature of KML will ensure that your data can be efficiently viewed in Google Earth. Using Regions, you can supply separate levels of detail for the data, so that fine details are loaded only when the user is close enough to discern them. The section on Super-Overlays in the KML documentation gives an example of creating a heirarchy of region-based network links in order to efficiently display a large set of imagery.

The open-source KML Regionator is a set of Python classes and scripts useful for generating and verifying Region-Based KML.

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值