Here’s the script I’m trying to run:
<?php
$lat = $_GET[lat];
$long = $_GET[long];
$mysongs3 = simplexml_load_file('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=845e721464167b9976ca031b0c3c66f3cc6563ee&query=restaurant&latitude='.$lat.'&longitude='.$long.'&results=2');
$lat2 = $mysongs3->Result[0]->Latitude;
$long2 = $mysongs3->Result[0]->Longitude;
$mysongs4 = simplexml_load_file('http://www.mapquestapi.com/directions/v1/route?key=Fmjtd%7Cluuan1urn9%2Cb0%3Do5-968206&from='.$lat.', '.$long.'&to='.$lat2.', '.$long2.'&callback=renderNarrative&outFormat=xml');
echo $mysongs4->route[0]->time;
?>
It doesn’t echo anything.
It’s utilizing the MapQuest and Yahoo API (though I know that the problem is at the MapQuest API bit, because if I remove the MapQuest bit and echo it, it works). The API key is correct, btw.
$_GET[lat] is 33.8524925 and
$_GET[long] is -117.73242200000001 .
The call to MapquestAPI does return the following document:
As you can see at the end, the
<route />element is empty. That is whyIs empty, too. If it would be different you would have a real problem.
If you expect there to have something, contact the API vendor for your support options.
Additionally I suggest you, that you create variables for the URLs so that you can debug which URLs you are actually requesting. Not that you have an error in building the URIs. Take care.
Turns out that this is actually your issue. You need to request the API with the correct URI otherwise it does not work. Double check that you remove any spaces for the
lat,longpairs, the correct URI must look like:Using that with
simplexml_load_fileworks fine, see the example:Output: