2012-06-05 1 views
1

GooRSS 피드를 Google Maps API v3에 표시해야합니다. 이 피드는 다음과 같은 절차를 통해 생성됩니다GeoRSS 피드의 변경 사항을 표시하는 데 Google Maps API v3이 너무 오래 걸립니다.

  1. 사용자 유형을 키워드에
  2. 감사하는 PHP 코드, RSS 파일은 3 개의 다른 기존의 RSS 피드에서 키워드가 포함 된 뉴스 항목을 고려하여 작성됩니다.
  3. 이 RSS 파일의 링크가 Metacarta RSS Geotagger 서비스에 주어진다 나는 KmlLayer를위한 인수로 GeoRSS를에 대한 링크를 제공하는 경우 (http://labs.metacarta.com/rss-geotagger/)
  4. 얻어진 GeoRSS를 파일도 (KML 파일로 변환해야합니다 기능을 사용하면 Google지도는 바다를 확대/축소합니다.) 이를 위해 내가 geonames.org
  5. 결과 URL의 GeoRSS를 KML에 변환기를 사용하고하는 것은 다음 KmlLayer를 함수 내 첫 번째 시도에서

에 대한 인수로 전달되어, 모두 괜찮 았는데. 그러나 새 키워드를 입력하면 Google지도에서 내 키워드의 마커를 이전 키워드와 함께 표시합니다. 새 KML 레이어가 표시 될 때까지 (물론 웹 브라우저의 새로 고침 버튼을 클릭 한 후) 약 15 분이 걸렸습니다. 수정 된 GeoRSS 피드가 새 키워드를 입력 한 직후에지도에 표시되도록이 문제를 해결할 수있는 방법이 있습니까?

새 사용자의 하이퍼 링크 수 제한으로 인해 여기에 소스 코드를 입력합니다. http://denizseeu.comule.com/ 의 I가 사용하고 파일입니다을 : 당신은 여기에서 파일을 액세스 할 수 있습니다 home.html을, my_rss.php, rss.xml을하고

home.html을을 map.html - 입력에 사용되는 첫 번째 페이지를하고

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Home</title> 
    <style type="text/css"> 
     #keyword 
     { 
      color:grey; 
      font: italic 12pt Arial; 
     } 
    </style> 
</head> 
<body> 
    <form name ="form1" method ="POST" action = "my_rss.php"> 
     <input type="Text" onblur="if(this.value=='') { this.value='Enter keyword'; this.style.color='grey'; this.style.font='italic 12pt Arial'; }" onfocus="if(this.value=='Enter keyword') { this.value=''; this.style.color='#111111'; this.style.font='normal 12pt Arial'; }" value="Enter keyword" name="keyword" id="keyword"> 
     <input type="Submit" name="Submit1" value= "Show news on map" /> 
    </form> 
</body> 
</html> 

my_rss.php 키워드를 확인하는 -은 RSS 파일을 생성 PHP 파일

<html> 
<head> 
<title>Redirecting...</title> 
<meta http-equiv="refresh" content="0;URL=map.html"> 
</head> 

<body> 
<?php 
    $keyword = $_POST['keyword']; 
    $URL = array("http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml","http://feeds.bbci.co.uk/news/world/rss.xml?edition=uk","http://rss.cnn.com/rss/edition.rss"); 
    $output = " 
<rss version=\"2.0\"> 
    <channel> 
     <title>RSS collection</title> 
       "; 
for($y=0;$y<count($URL);$y++) 
{ 
    $rss[$y] = simplexml_load_file($URL[$y]); 

    foreach ($rss[$y]->channel->item as $item) 
    { 
      if(preg_match("/".$keyword."/",$item->title,$result)) 
      {      
       $output .= " 
          <item> 
           <title>". $item->title ."</title> 
           <description>". $item->description ."</description> 
           <link>"; 
       $link=$item->link; 
       $link = str_replace('&', '&amp;', $link); 
       $output .= $link ."</link> 
          </item> 
          "; 
      } 
    } 
} 
$output .= "</channel></rss>"; 

header ('Content-type: text/html; charset=utf-8'); 

echo $output; 

$xml = "rss.xml"; 
$file = fopen($xml, 'w') or die("can't open file"); 
fwrite($file, $output); 
fclose($file); 
?> 
</body> 
</html> 

map.html - Google지도 API

<!DOCTYPE html> 
<html> 
<head> 
    <title>Welcome to my GeoRSS map</title> 
    <meta name="viewport" 
    content="width=device-width, initial-scale=1.0, user-scalable=no"> 
    <meta charset="UTF-8"> 
    <style type="text/css"> 
    html, body, #map_canvas { 
     margin: 0; 
     padding: 0; 
     height: 100%; 
    } 
    </style> 
    <script type="text/javascript" 
    src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
     var map; 
     var initial_point = new google.maps.LatLng(42.02,20.97); 
     function initialize() { 
     var myOptions = { 
     zoom: 2, 
     center: initial_point, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); 

    var geoRSS = new google.maps.KmlLayer('http://ws.geonames.org/rssToGeoRSS?type=kml&feedUrl=http%3A%2F%2Flabs.metacarta.com%2Frss-geotagger%2Ftag%2F%3Furl%3Dhttp%253A%252F%252Fdenizseeu.comule.com%252Frss.xml'); 
    geoRSS.setMap(map); 
    } 

    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
</head> 
<body> 
    <div id="map_canvas"></div> 
</body> 
</html> 

답변

1

와 웹 페이지는 KmlLayer를 KML을 캐시, 그리고 무엇인지 다시로드 분명히 같은 파일은 구글이 KML을 다시로드하고 레이어 타일을 새로 발생하지 않습니다.

KML URL에 임의의 더미 매개 변수 (아마도 시간을 기준로 또는 Math.random)를 추가하십시오. 그러면 Google이 매번 새로운 URL을 얻고지도에 올바른 데이터를 얻을 수있는 최상의 기회입니다.

참고 : Google의 KML 처리는 블랙 박스입니다. 더미 매개 변수에 속지 않을 수 있습니다.