topical media & game development
professional-ria-03-GeoCodeProxy.htm / htm
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Yahoo! Geocoder</title>
<link rel=StyleSheet href="../../stylesheets/RIAStyle1.css" TYPE="text/css">
<script src="../../scripts/createXMLHttpRequest.js" type="text/javascript"></script>
<script "text/javascript">
//<![CDATA[>
// global vars
var __xmlhttp = false;
var __lat = null;
var __lon = null;
var __appid = "YahooDemo";
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
function callWS(target){
if(target !== ""){
if (!xmlhttp) {xmlhttp = createXMLHttpRequest();}
alert("callWS: target: "+target);
var url = '../../phpscripts/geocoder.php?' + target;
xmlhttp.open('GET', url, true);
xmlhttp.onreadystatechange = function() {
alert("callWS: onreadystatechange: "+xmlhttp.readyState );
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('Result').innerHTML = '';
document.getElementById('State').innerHTML = 'Done.';
alert("xmlhttp.responseText:" + xmlhttp.responseText);
getLatLon(xmlhttp.responseText);
} else {
document.getElementById('State').innerHTML = "Working...";
}
};
alert("callWS: sending: "+xmlhttp);
xmlhttp.send(null);
}
}
function getLatLon(result){
var start = (result.search(/<Latitude>/) +10 );
var end = result.search(/<\/Latitude>/);
var lat = result.substr(start, (end -start) );
start = (result.search(/<Longitude>/) +11 );
end = result.search(/<\/Longitude>/);
var lon = result.substr(start, (end -start) );
document.getElementById("Latitude").innerHTML = lat;
document.getElementById("Longitude").innerHTML = lon;
document.getElementById("State").innerHTML = "";
xmlhttp = false;
}
function onLoad() {
}
function callGeocode() {
var query = document.getElementById("geoquery").value;
var uri = "http://api.local.yahoo.com/MapsService/V1/geocode?appid="+__appid+"&output=xml&location=" + query;
callWS(uri);
}
//]]>
</script>
</head>
<body onload="onLoad()">
<div id="header">
<h1>Simple Geocoding Example </h1>
<h2>Input a loose location description, and Yahoo's Geocoding service returns a Latitude / Longitude pair</h2>
</div>
<br />
<div class="inputelement"><button onClick="callGeocode()">GEOCODE LOCATION</button>
<input id="geoquery" value="1300 N. 17th St, Arlington VA" size="50"></input>
</div>
<br />
<div id="State"></div>
<div id="Result"></div>
<p>Latitude: <span id="Latitude" style="font-weight:bold"></span> </p>
<p>Longitude: <span id="Longitude" style="font-weight:bold"></span> </p>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.