rss - Google Maps API v3 takes too long to show changes in the GeoRSS feed -
i need display georss feed on google maps api v3. feed created through following procedures:
- the user types in keyword
- thanks php code, rss file created taking news items containing keyword 3 different existing rss feeds.
- the link of rss file given metacarta rss geotagger service ( http://labs.metacarta.com/rss-geotagger/ )
- the obtained georss file must converted kml file (if give link georss argument kmllayer function, google maps zoom ocean). purpose i'm using georss kml convertor of geonames.org
- the resulting url passed argument kmllayer function
at first try, worked fine. when entered new keyword, google maps showed markers try previous keyword. took 15 minutes until new kml layer displayed (of course, after clicking refresh button of web browser). there way solve problem modified georss feed shown on map after typing in new keyword?
due hyperlink number restrictions new user, type sourcecodes here. can access files here: http://denizseeu.comule.com/ files i'm using are: home.html, my_rss.php, rss.xml , map.html
home.html - first page used typing , confirming keyword
<!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 - php file creates rss file
<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 $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('&', '&', $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 - web page google maps api
<!doctype html> <html> <head> <title>welcome 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>
kmllayer caches kml, , reloading apparently same file doesn't cause google reload kml , refresh layer tiles.
add random dummy parameter (perhaps based on time, or math.random) kml url. ensure google gets fresh url each time , best chance of getting right data in map.
note: google's kml handling black box. may not fooled dummy parameter.
Comments
Post a Comment