2

我有一个带有 blogspot 的旅游博客。我有一个页面,其中显示了迄今为止所走路径的世界地图。为此,我使用博客 API 来检索每个帖子的位置,如下所示:

<script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts?callback=handleResponse&amp;key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">

我的问题是,似乎只检索了最后的帖子,而忽略了第一个帖子。在以下链接中,完整路径应包含阿根廷南部的所有区域,并链接到显示的当前路径。

http://el-gato-lindo.blogspot.com/p/map.html

生成地图的完整代码如下:

<html>
<body>

<div id="content">
</div>
<div align="center" id="googleMap" style="height: 900px; width: 620px;">
</div>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&amp;sensor=false">
</script>

<script src="http://maps.google.com/maps/api/js?sensor=false&amp;libraries=geometry" type="text/javascript"></script>

<script>
var Lat = new Array();
var Lng = new Array();
var Place = new Array();
var TitlePost = new Array();
var UrlPost = new Array();
var DatePost = new Array();

// Get latitude/longitude from Blogger
function handleResponse(response) {
 for(i=0; i< response.items.length; i++){
  if(response.items[i].location != undefined){
   Lat.push(response.items[i].location.lat);
   Lng.push(response.items[i].location.lng);
   Place.push(response.items[i].location.name);
   TitlePost.push(response.items[i].title);
   UrlPost.push(response.items[i].url);
   DatePost.push(response.items[i].published);
  }
 }
}

// Distance btw two places in km
function calcDistance(p1, p2){
 return (google.maps.geometry.spherical.computeDistanceBetween(p1,p2)/1000).toFixed(2);
}

// Name of months for date formatting
var m_names = new Array();
m_names.push("January"); 
m_names.push("February"); 
m_names.push("March"); 
m_names.push("April"); 
m_names.push("May"); 
m_names.push("June"); 
m_names.push("July"); 
m_names.push("August"); 
m_names.push("September"); 
m_names.push("October"); 
m_names.push("November"); 
m_names.push("December");

// Create the map based on locations retrieved from Blogger
function initialize(){
 // Get all latitude and longitude
 var pos = new Array();

 // Get the path
 for(var i=0; i<Lat.length; i++){
  pos[i]=new google.maps.LatLng(Lat[i],Lng[i]);
 }

 // Get the last position
 var lastpos=new google.maps.LatLng(Lat[0],Lng[0]);

 // Create the map
 var mapProp = {
  center:lastpos,
  zoom:4,
  mapTypeId:google.maps.MapTypeId.TERRAIN,
  navigationControl:true, 
  streetViewControl:false
  };

 var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

 // Create the path
 var flightPath = new google.maps.Polyline({
  path:pos,
  strokeColor:"#EE0000",
  strokeOpacity:0.6,
  strokeWeight:7,
  clickable:false,
  map:map
 });

 // Create invisible marker at each destination
 var markerPos = new Array();
 var infowindow = null;

 for(var i=0; i<pos.length; i++){
  marker=new google.maps.Marker({
   position:pos[i],
   icon: {
    path: google.maps.SymbolPath.CIRCLE,
    scale:5,
    fillOpacity:0,
    strokeOpacity:0
   },
   clickable:true,
   map:map
  });

  // Click on marker: Show infowindow with articles
  google.maps.event.addListener(marker, 'click', function() {

    // Articles posted within a given distance from point clicked will be shown
    var toldist = 2048 / Math.pow(2,map.zoom); //km

    str = '<div id="infowindow_listposts">';

    for(var j=0; j<pos.length; j++){
      if(pos[j] === this.position){
       var optplace = j;
       str += "<h1>
" + Place[j] + "</h1>
<br>";
     }
    }
    str += "<ul>";
    for(var j=0; j<pos.length; j++){
     var dist = calcDistance(pos[j],this.position);

     if(dist < toldist){
      date = new Date(DatePost[j]);
      str += "<li> <h2>
<a href='" + UrlPost[j] + "'>" + TitlePost[j] + "</a> <i>(";
      str += m_names[date.getMonth()] + " " + date.getDate() + ", ";
      str += date.getFullYear() + ") </i></h2>
</li>
";
     }
    }
    str += "</ul>
";
    str += "<i> Articles shown were written less than ";
    if(toldist >= 1)
     str += toldist + "km away from ";
    else
     str += 1000*toldist + "m away from ";
    str += Place[optplace] + ".</i>";

    str += "</div>
";

    if (infowindow){
     infowindow.close();
    }

    infowindow = new google.maps.InfoWindow({
     content:str
    });

    infowindow.open(map,this);
   });

  markerPos.push(marker);
 }

 // Create the marker of last position
 var lastmarker=new google.maps.Marker({
   position:lastpos,
   clickable:false,
   map:map
 });
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>


<script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts?callback=handleResponse&amp;key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">
</script>

</body>
</html>

非常感谢你的帮助!我目前正在旅行,很难解决这个问题!

尼古拉斯

4

1 回答 1

2

尝试更换

 <script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts?callback=handleResponse&amp;key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">

 <script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts/default?redirect=false&start-index=1&max-results=500?callback=handleResponse&amp;key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">
于 2013-06-04T04:38:19.817 回答