Hi David, The proxy is quite simple once you grasp the concept. As you can see in my code, I point the GDownloadURL to a PHP script (the proxy). The PHP script runs on the server side so it gets around the issue that JavaScript has with cross-domain access restrictions. The PHP script simply pulls the XML data off the cross-domain URL and loads it into memory so it can dump the data back out to JavaScript in your browser and the GDownloadURL script can process the XML data as if you had done it in the browser. I can say as a novice programmer it took me a little while to get the scripts to do exactly what I was looking for but the community here really helped me out.
In your script, if you replace "example4.xml" in the GDownloadURL with "xmlproxy.php" and then put this code in a file called xmlproxy.php in the same directory as your html file it would work (assuming your script was set up to process the elements correctly). <?php $url = "http://www.google.com/ig/api?weather=61801"; //fetch XML feed from posted url $ch = curl_init(); $timeout = 60; $userAgent = $_SERVER['HTTP_USER_AGENT']; $header[] = "Content-type: text/xml"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header ); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); $response = curl_exec($ch); if (curl_errno($ch)) { // write error to log file } else { curl_close($ch); echo $response; } ?> The problem with the URL you are using is that it doesn't return lat and long coordinates, at least when I tried they were empty strings. If you give me an example URL that returns XML data with lat/longs I could set up a demo. Hope this helps, Chad On Dec 10, 5:20 pm, David Miao <[EMAIL PROTECTED]> wrote: > Dear Chad, > > I appreciate your suggestion very much. Your program runs perfect. Do > you know how to use javascript to read xml data from different sitefirefox? > Larry suggests me to useproxy. I still do not know how to do > it. Thank you very much for your help. > > Best, David > > On Dec 9, 4:47 pm, Rainman <[EMAIL PROTECTED]> wrote: > > > > > David, > > > I am doing similar calls on my site and I found (with much help from > > this community) that a very simple PHP script as aproxysolved my > > problems. > > > Here is my map:http://www.udfcd.org/FWP/LDAD/gmap.html > > > If you click on the Archived ALERT tab and click Update Map with the > > default options you will see it in action. > > > I use the this, 'GDownloadUrl("xmlproxy.php?type=rainarchive&ME=" + ME > > + "&DE=" + DE + "&YE=" + YE+ "&HE=" + HE, function(data)' instead of a > > direct call to the XML file. I pass the date and time variable > > information from the HTML form to the javascript function and let the > > PHP script do the legwork for reading the XML file and storing it > > locally. > > > Here is the relevent part of the PHP script: > > <?php > > if ($_GET['type'] == "rainarchive") { > > $url = "http://alert2.udfcd.org/cgi-bin/reportgen.new?TPT=tpt/ > > xml_rain.tpt&CFG=lst/fslrain.lst&TIM=tim/xml_rain.tim&YE=" . $_GET > > ['YE'] . "&ME=" . $_GET['ME'] . "&DE=" . $_GET['DE'] . "&HE=" . $_GET > > ['HE'];} > > > //fetch XML feed from posted url > > $ch = curl_init(); > > $timeout = 60; > > $userAgent = $_SERVER['HTTP_USER_AGENT']; > > $header[] = "Content-type: text/xml"; > > > curl_setopt($ch, CURLOPT_URL, $url); > > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); > > curl_setopt($ch, CURLOPT_HTTPHEADER, $header ); > > curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); > > curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); > > curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); > > > $response = curl_exec($ch); > > > if (curl_errno($ch)) { > > $fl=fopen($logfile, "w"); > > fwrite($fl, curl_error($ch) . " url: " . $url); //write contents > > of error to log file > > fclose($fl);} else { > > > curl_close($ch); > > echo $response;} > > > ?> > > > I'm a weekend programmer and I was able to get this working for me > > with the help of this group. > > > If others see a better way to do this I'm open to suggestions as well. > > > Good luck! > > Chad > > > On Dec 8, 8:19 am, David Miao <[EMAIL PROTECTED]> wrote: > > > > Dear larry and all, > > > > I appreciate very much your valuable suggestions. Could you please > > > give me more detail suggestions how to modify my code if using Json to > > > call the xml data from the url "http://www.google.com/ig/api? > > > weather=61801"? since I am not very familar with network stuff. With > > > view source, you can see the code > > > fromhttp://abe-research.illinois.edu/Faculty/grift/Research/EBI/xhr-reque.... > > > I thank you again for your help. Have a good day! > > > > Sincerely, > > > > David > > > > On Dec 8, 12:37 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > > wrote: > > > > > On Dec 7, 7:10 pm, David Miao <[EMAIL PROTECTED]> wrote:> Dear > > > > Sir/Madam, > > > > > > I am asking for help to solve the question ofFirefoxcross site > > > > > domain. I am trying to develop a simple program to show weather info > > > > > on my map. I modified the program from Mr. Mike Williams' tutorial. > > > > > The program works very well for IE but not forFirefox. With IE, the > > > > > program shows three marks and weather infowindow when clicking the > > > > > markers. I guess it is the problem ofFirefoxcross-site. I spent days > > > > > and can not get it done. Any comments and suggestions are welcome. > > > > > > Link:http://abe-research.illinois.edu/Faculty/grift/Research/EBI/xhr-reque... > > > > > I get the same error in IE6 and FF: > > > > FF: > > > > Error: uncaught exception: [Exception... "Access to restricted URI > > > > denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" > > > > location: "http://maps.google.com/intl/en_us/mapfiles/139e/maps2.api/ > > > > main.js Line: 235"] > > > > > IE: > > > > Line: 235 > > > > Error: Permission denied > > > > > due to this URL: > > > > var url = "http://www.google.com/ig/api?weather=61801"; > > > > > You know what the problem is. There is only one way to solve the > > > > problem with XmlHttpRequest, aproxy. There are other solutions if > > > > you use JSON rather than XmlHttpRequest. > > > > > -- Larry- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
