Please read and follow the group's posting guidelines: http://groups.google.com/group/Google-Maps-API/web/suggested-posting-guidelines http://groups.google.com/group/Google-Maps-API/web/why-including-a-link-is-critical
-- Marcelo - http://maps.forum.nu -- On Oct 11, 11:57 am, James McLaren <[email protected]> wrote: > Ok so basically I am trying to create a simple php project for a hobby > that will get data from an RSS feed, parse it, and then write the > resulting data to a googlemap. So far I have succeeded in reading and > parsing using magpie rss, but when it comes to writing to the > googlemap I begin to have a few issues. Firstly these are the two > pieces of code I am using: > > PHP: > > <?PHP > > url = 'feed:http://www.cfa.vic.gov.au/incidents/ > incident_updates_rss.xml'; > $rss = fetch_rss($url); > > echo "Site: ", $rss->channel['title'], "<br>"; > foreach ($rss->items as $item ) { > $title = $item[title]; > $url = $item[link]; > $description = $item[description]; > echo "<a href=$url>$title</a></li><br>"; > > } > > reach ($rss->items as $item ) { > $title = $item[title]; > $url = $item[link]; > mysql_query("INSERT INTO `table` (`id`, `title`, `link`) VALUES > (NULL, '$title', '$url')")";} > > ?> > > <?php > require("phpsqlajax_dbinfo.php"); > > // Start XML file, create parent node > $doc = domxml_new_doc("1.0"); > $node = $doc->create_element("markers"); > $parnode = $doc->append_child($node); > // Iterate through the rows, adding XML nodes for each > while ($row = @mysql_fetch_assoc($result)){ > // ADD TO XML DOCUMENT NODE > $node = $doc->create_element("marker"); > $newnode = $parnode->append_child($node); > > $newnode->set_attribute("name", $row['name']); > $newnode->set_attribute("address", $row['address']); > $newnode->set_attribute("lat", $row['lat']); > $newnode->set_attribute("lng", $row['lng']); > $newnode->set_attribute("type", $row['type']); > > } > > $xmlfile = $doc->dump_mem(); > echo $xmlfile; > > function parseToXML($htmlStr) > { > $xmlStr=str_replace('<','<',$htmlStr); > $xmlStr=str_replace('>','>',$xmlStr); > $xmlStr=str_replace('"','"',$xmlStr); > $xmlStr=str_replace("'",''',$xmlStr); > $xmlStr=str_replace("&",'&',$xmlStr); > return $xmlStr; > > } > > this uses MagpieRSS to read the data from the feed and also utilizes > the google code to write it to an xml file (one other side note. The > description field contains many different fields so and hints as to > how to parse this field seperatly would be appreciated). And this is > the html that I am using... provided courtesy of google =) > > <!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 Maps AJAX + MySQL/PHP Example</title> > <script src="http://maps.google.com/maps? > file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ- > jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg" > type="text/javascript"></script> > > <script type="text/javascript"> > //<![CDATA[ > > var iconBlue = new GIcon(); > iconBlue.image = 'http://labs.google.com/ridefinder/images/ > mm_20_blue.png'; > iconBlue.shadow = 'http://labs.google.com/ridefinder/images/ > mm_20_shadow.png'; > iconBlue.iconSize = new GSize(12, 20); > iconBlue.shadowSize = new GSize(22, 20); > iconBlue.iconAnchor = new GPoint(6, 20); > iconBlue.infoWindowAnchor = new GPoint(5, 1); > > var iconRed = new GIcon(); > iconRed.image = 'http://labs.google.com/ridefinder/images/ > mm_20_red.png'; > iconRed.shadow = 'http://labs.google.com/ridefinder/images/ > mm_20_shadow.png'; > iconRed.iconSize = new GSize(12, 20); > iconRed.shadowSize = new GSize(22, 20); > iconRed.iconAnchor = new GPoint(6, 20); > iconRed.infoWindowAnchor = new GPoint(5, 1); > > var customIcons = []; > customIcons["restaurant"] = iconBlue; > customIcons["bar"] = iconRed; > > function load() { > if (GBrowserIsCompatible()) { > var map = new GMap2(document.getElementById("map")); > map.addControl(new GSmallMapControl()); > map.addControl(new GMapTypeControl()); > map.setCenter(new GLatLng(47.614495, -122.341861), 13); > > GDownloadUrl("phpsqlajax_genxml.php", function(data) { > var xml = GXml.parse(data); > var markers = xml.documentElement.getElementsByTagName > ("marker"); > for (var i = 0; i < markers.length; i++) { > var name = markers[i].getAttribute("name"); > var address = markers[i].getAttribute("address"); > var type = markers[i].getAttribute("type"); > var point = new GLatLng(parseFloat(markers[i].getAttribute > ("lat")), > parseFloat(markers[i].getAttribute > ("lng"))); > var marker = createMarker(point, name, address, type); > map.addOverlay(marker); > } > }); > } > } > > function createMarker(point, name, address, type) { > var marker = new GMarker(point, customIcons[type]); > var html = "<b>" + name + "</b> <br/>" + address; > GEvent.addListener(marker, 'click', function() { > marker.openInfoWindowHtml(html); > }); > return marker; > } > //]]> > </script> > > </head> > > <body onload="load()" onunload="GUnload()"> > <div id="map" style="width: 500px; height: 300px"></div> > </body> > </html> > > however when i run the html the output i get is as follows: > > {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540 {\fonttbl\f0\fmodern > \fcharset0 Courier;} {\colortbl; > \red255\green255\blue255;\red103\green102\blue0;\red250\green250\blue250;\red0\green10\blue138; > \red19\green135\blue0;\red136\green0\blue0;\red6\green102\blue103;} > \paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0 > \deftab720 \pard\pardeftab720\ql\qnatural \f0\fs18 \cf0 channel > ['title'], " > ";\ foreach ($rss->items as $item ) \{\ $title = $item[title];\ $url = > $item[link];\ echo "$title > ";\ \}\ \ reach ($rss->items as $item ) \{\ $title = $item[title];\ > $url = $item[link];\ // mysql_query("INSERT INTO `table` (`id`, > `title`, `link`) VALUES (NULL, \ //'$title', '$url')")";\ \}\ ?>\ \ > \pard\pardeftab720\sl300\ql\qnatural \fs24 \cf2 \cb3 \cf0 > create_element\cf2 (\cf5 "markers"\cf2 );\cf0 \ $parnode \cf2 =\cf0 > $doc\cf2 ->\cf0 append_child\cf2 (\cf0 $node\cf2 );\ \cf6 // Iterate > through the rows, adding XML nodes for each\cf0 \ \cf4 while\cf0 \cf2 > (\cf0 $row \cf2 =\cf0 \cf7 @mysql_fetch_assoc\cf2 (\cf0 $result\cf2 ))\ > {\cf0 \ \'a0 \cf6 // ADD TO XML DOCUMENT NODE\cf0 \ \'a0 $node \cf2 = > \cf0 $doc\cf2 ->\cf0 create_element\cf2 (\cf5 "marker"\cf2 );\cf0 \ > \'a0 $newnode \cf2 =\cf0 $parnode\cf2 ->\cf0 append_child\cf2 (\cf0 > $node\cf2 );\cf0 \ \ \'a0 $newnode\cf2 ->\cf0 set_attribute\cf2 (\cf5 > "name"\cf2 ,\cf0 $row\cf2 [\cf5 'name'\cf2 ]);\cf0 \ \'a0 $newnode\cf2 > ->\cf0 set_attribute\cf2 (\cf5 "address"\cf2 ,\cf0 $row\cf2 [\cf5 > 'address'\cf2 ]);\cf0 \ \'a0 $newnode\cf2 ->\cf0 set_attribute\cf2 > (\cf5 "lat"\cf2 ,\cf0 $row\cf2 [\cf5 'lat'\cf2 ]);\cf0 \ \'a0 $newnode > \cf2 ->\cf0 set_attribute\cf2 (\cf5 "lng"\cf2 ,\cf0 $row\cf2 [\cf5 > 'lng'\cf2 ]);\cf0 \ \'a0 $newnode\cf2 ->\cf0 set_attribute\cf2 (\cf5 > "type"\cf2 ,\cf0 $row\cf2 [\cf5 'type'\cf2 ]);\cf0 \ \cf2 \}\cf0 \ \ > $xmlfile \cf2 =\cf0 $doc\cf2 ->\cf0 dump_mem\cf2 ();\cf0 \ echo > $xmlfile\cf2 ;\cf0 \ \ \ \cf4 function\cf0 parseToXML\cf2 (\cf0 > $htmlStr\cf2 )\cf0 \ \cf2 \{\cf0 \ $xmlStr\cf2 =\cf0 str_replace\cf2 > (\cf5 '<'\cf2 ,\cf5 '<'\cf2 ,\cf0 $htmlStr\cf2 );\cf0 \ $xmlStr\cf2 = > \cf0 str_replace\cf2 (\cf5 '>'\cf2 ,\cf5 '>'\cf2 ,\cf0 $xmlStr\cf2 ); > \cf0 \ $xmlStr\cf2 =\cf0 str_replace\cf2 (\cf5 '"'\cf2 ,\cf5 '"'\cf2 , > \cf0 $xmlStr\cf2 );\cf0 \ $xmlStr\cf2 =\cf0 str_replace\cf2 (\cf5 > "'"\cf2 ,\cf5 '''\cf2 ,\cf0 $xmlStr\cf2 );\cf0 \ $xmlStr\cf2 =\cf0 > str_replace\cf2 (\cf5 "&"\cf2 ,\cf5 '&'\cf2 ,\cf0 $xmlStr\cf2 );\cf0 \ > \cf4 return\cf0 $xmlStr\cf2 ;\cf0 \ \cf2 \}} > > any thoughts as to why it would be doing this... and any thoughts as > to how i could fix it would be greatly appreciated. > > Thanks > > James Thanks > > James --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en -~----------~----~----~----~------~----~------~--~---
