<slide title="Geocoding API">
<blurb>
Finally, a free geocoding API
</blurb>

<example title="REST Query to look up an address" result="0" fontsize="1.8em" marginright="0em"><![CDATA[http://local.yahooapis.com/MapsService/V1/geocode?appid=rlerdorf&location=:-:location:-:]]></example>

<example hide="1" result="1" title="Returned XML"><![CDATA[<?php
$loc = urlencode(':-:location:-:');
if(!$data = @file_get_contents("presentations/slides/intro/geo_{$loc}.xml"))
  $data = file_get_contents("http://local.yahooapis.com/MapsService/V1/geocode?appid=rlerdorf&location=$loc");
$data = preg_replace("|<(/.*?)>|","<\\1>\n",trim($data));
$data = preg_replace("|\">|","\">\n",$data);
echo nl2br(htmlspecialchars($data));
?>]]></example>

<example fontsize="1.2em" title="We can parse it like this" result="1" marginright="0em" required_extension="simplexml"><![CDATA[<?php
  $url  = 'http://local.yahooapis.com/MapsService/V1/geocode';
  $url .= '?appid=rlerdorf&location='.urlencode(':-:location:-:');
  $xml = simplexml_load_file($url); 
  $ret['precision'] = (string)$xml->Result['precision'];
  $ret['warning'] = (string)$xml->Result['warning'];
  foreach($xml->Result->children() as $key=>$val) {
    if(strlen($val)) $ret[(string)$key] =  (string)$val;
  }
  echo "<pre>"; print_r($ret); echo "</pre>";
?>]]></example>

<example title="Closest Match" result="0" fontsize="1.8em" marginright="0em"><![CDATA[http://local.yahooapis.com/MapsService/V1/geocode?appid=rlerdorf&location=701%20First,%20Sunnyvale]]></example>

<example title="Returned XML" result="0" fontsize="1.4em" marginright="0em"><![CDATA[<ResultSet xsi:schemaLocation="urn:yahoo:maps http://local.yahooapis.com/MapsService/V1/GeocodeResponse.xsd">
 <Result precision="address" 
         warning="The exact location could not be found, 
                  here is the closest match: 701 First Ave, Sunnyvale, CA 94089">
  <Latitude>37.416384</Latitude>
  <Longitude>-122.024853</Longitude>
  <Address>701 FIRST AVE</Address>
  <City>SUNNYVALE</City>
  <State>CA</State>
  <Zip>94089-1019</Zip>
  <Country>US</Country>
 </Result>
</ResultSet>]]></example>

<link fontsize="3em" marginleft="3em" leader="Docs: " href="http://developer.yahoo.com/maps/"/>

</slide>
