2010-07-24 64 views
0

得到地理RSS的地理数据,这是我的代码,具有地理RSS从谷歌地图rss如何通过谷歌AJAX供稿API

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Google AJAX Feed API - Simple Example</title> 
    <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 

    google.load("feeds", "1"); 

    function initialize() { 
     var feed = new google.feeds.Feed("http://maps.google.com/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=259e&msa=0&output=georss&msid=109685068115364659392.00048b5b630141d82b83a"); 

     feed.load(function(result) { 
     console.log(result.feed) 

     }); 

    } 
    google.setOnLoadCallback(initialize); 

    </script> 
    </head> 
    <body> 
    <div id="feed"></div> 
    </body> 
</html> 

,我无法找到关于地理数据萤火虫,

所以我应该怎么办..

感谢

更新:

地理数据(在地理RSS)我想是这样的:

<georss:point> 
     39.965015 116.362381 
    </georss:point> 

<gml:LineString> 

     <gml:posList> 
     39.992191 116.417938 
     39.968254 116.466698 
     39.939568 116.451591 
     39.959045 116.411079 
     </gml:posList> 
    </gml:LineString> 

这不能获得使用谷歌AJAX API。

所以我应该怎么办..

回答

1

你需要自行加载JSON的XML饲料的例子以便能够按原样获取原始XML Feed。使用JSON订阅源,它将删除所有,但删除标准RSS和Atom标记的,然后转换为JSON。

设置结果格式XML作为

var feed = new google.feeds.Feed("..."); 
feed.setResultFormat(google.feeds.Feed.XML_FORMAT); 

这里是一个修改的负载功能打印XML命名空间的元素如georss:pointgml:LineString

feed.load(function(result) { 
    var georssNS = "http://www.georss.org/georss"; 
    var gmlNS = "http://www.opengis.net/gml"; 
    var items = result.xmlDocument.getElementsByTagName("item"); 

    for(var i = 0; i < items.length; i++) { 
     // get <georss:point> 
     var georss = google.feeds.getElementsByTagNameNS(items[i], georssNS, "point")[0]; 
     if(georss) { 
      console.log(georss) 
     } 
     // get <gml:LineString> 
     var lineString = google.feeds.getElementsByTagNameNS(items[i], gmlNS, "LineString")[0]; 
     if(lineString) { 
      console.log(lineString); 
     } 
    } 
}); 
0

从谷歌AJAX API代码园地,工程

http://code.google.com/apis/ajax/playground/?exp=feeds#load_feed

/* 
* How to load a feed via the Feeds API. 
*/ 

google.load("feeds", "1"); 

// Our callback function, for when a feed is loaded. 
function feedLoaded(result) { 
    if (!result.error) { 
    // Grab the container we will put the results into 
    var container = document.getElementById("content"); 
    container.innerHTML = ''; 

    // Loop through the feeds, putting the titles onto the page. 
    // Check out the result object for a list of properties returned in each entry. 
    // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON 
    for (var i = 0; i < result.feed.entries.length; i++) { 
     var entry = result.feed.entries[i]; 
     var div = document.createElement("div"); 
     div.appendChild(document.createTextNode(entry.title)); 
     container.appendChild(div); 
    } 
    } 
} 

function OnLoad() { 
    // Create a feed instance that will grab Digg's feed. 
    var feed = new google.feeds.Feed("http://maps.google.com/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=259e&msa=0&output=georss&msid=109685068115364659392.00048b5b630141d82b83a"); 

    // Calling load sends the request off. It requires a callback function. 
    feed.load(feedLoaded); 
} 

google.setOnLoadCallback(OnLoad); 
+0

嗨brickysam26,看看更新。 – zjm1126 2010-07-24 09:33:03