the function that sends a rest request to yahoo to get the lat & longitude of the address in XML. Then it parses the address data XML into an array. It all works and I get a yahoo map. The problem is I have to trap for errors like 503 service unavailable. I get the XML address data results from this XML.
Here is and example of the XML geocode results:
1. <?xml version="1.0" encoding="UTF-8"?>
2.
3. <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4. xmlns="urn:yahoo:maps"
5. xsi:schemaLocation="urn:yahoo:maps http://local.yahooapis.com/MapsService/V1/GeocodeResponse.xsd">
6. <Result precision="address">
7. <Latitude>37.416384</Latitude>
8.
9. <Longitude>-122.024853</Longitude>
10. <Address>701 FIRST AVE</Address>
11. <City>SUNNYVALE</City>
12. <State>CA</State>
13.
14. <Zip>94089-1019</Zip>
15. <Country>US</Country>
16. </Result>
17. </ResultSet>
however this is the error results if the address is wrong
<Error xmlns="urn:yahoo:api">
The following errors were detected:
<Message>error message</Message>
</Error>
I don't know how to get this error message then I have to parse it?This error message should go into $htmlMessage. BUt how?
This is the function:
If you notice the $htmlMessage is null. I need to pass the $htmlMessage into the function. I don't know how to get it from Yahoo. It seems like the $apiURL should have a callback function of some kind.
function addAddress($address,$htmlMessage=null){
if (!is_string($address)){
die("All Addresses must be passed as a string");
}
$apiURL = "http://local.yahooapis.com/MapsService/V1/geocode?appid=JezVqMLV34G_VJeKk_o8kM12GbWa1PiTotJPt6OxwowFgMb73vEJ.VUdXXp92w--&location=";
$addressData = file_get_contents($apiURL.urlencode($address));
$results = $this->xml2array($addressData);
if (empty($results['ResultSet']['Result']['Address'])){
$pointer = count($this->invalidPoints);
$this->invalidPoints[$pointer]['lat']= $results['ResultSet']['Result']['Latitude'];
$this->invalidPoints[$pointer]['long']= $results['ResultSet']['Result']['Longitude'];
$this->invalidPoints[$pointer]['passedAddress'] = $address;
$this->invalidPoints[$pointer]['htmlMessage'] = $htmlMessage;
}else{
$pointer = count($this->validPoints);
$this->validPoints[$pointer]['lat']= $results['ResultSet']['Result']['Latitude'];
$this->validPoints[$pointer]['long']= $results['ResultSet']['Result']['Longitude'];
$this->validPoints[$pointer]['passedAddress'] = $address;
$this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;
}
}