First we have a php that takes the content of the specified URL.
(I am using this to use the googleMAP reverse geocoding.)
//proxy.php
<?php>
$content= file_get_contents("http://maps.google.com/maps/api/geocode/xml?latlng=36.9125,30.6897222&sensor=true");
echo $content;
?>
Then we have a basic XMLHTTPRequest JavaScript;
<html>
<head>
<script type="text/javascript">
var xml;
function loadXMLDoc()
{
var file = "proxy.php";//our php file
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
xml = xmlhttp.responseText;
}
}
xmlhttp.open("GET",file,false);
xmlhttp.send();;
}
function parseXML(){
try{
loadXMLDoc();
xml = (new DOMParser()).parseFromString(xml, "text/xml");
path='/GeocodeResponse/result/address_component[type="route"]/long_name/text()';
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
//alert("fsdgsdg"+nodes[0].nodeValue);
document.write(nodes[0].nodeValue);
document.write("
");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();
while (result)
{
alert(result.nodeValue);
document.write(result.nodeValue);
document.write("
");
result=nodes.iterateNext();
}
}
}catch(err){
alert(err);
}
}
</script>
</head>
<body onLoad="parseXML();">
</body>
</html>
//-->
</script>
</head>
This is an example implementation. Maybe you need to change some part of the program but this example is to get the idea behind the solution.
Take Care:)
Hiç yorum yok:
Yorum Gönder