0
<a href="http://maps.apple.com/?ll=<?php echo $_GET[q] ?>" style="text-
decoration:none;color:gray;"><div class="box" style="position:absolute;top:0px;left:0px;font-family:Lato;"><span style="float:left;">Directions</span><span style="color:#F2473F;float:right;">About <?php
$lat = $_GET['lat'];
$long = $_GET['long'];
$q = $_GET['q'];
$mysongs = simplexml_load_file('http://www.mapquestapi.com/geocoding/v1/address?key=Fmjtd%7Cluuan1urn9%2Cb0%3Do5-968206&location=' . $q . '&callback=renderGeocode&format=xml');
$lat2 = $mysongs->results[0]->result[0]->result[0]->locations[0]->location[0]->latLng[0]->lat;
$long2 = $mysongs->results[0]->result[0]->result[0]->locations[0]->location[0]->latLng[0]->lng;
$mysongs4 = simplexml_load_file('http://www.mapquestapi.com/directions/v1/route?key=Fmjtd%7Cluuan1u2nh%2C2a%3Do5-96rw5u&from=' . $lat . ',' . $long . '&to=' . $lat2 . ',' . $long2 . '&callback=renderNarrative&outFormat=xml');
$vari = $mysongs4->route[0]->time;
$vari = $vari / 60;
echo round($vari);
?> minutes</span><br></div>

What did I do wrong? The variables $lat2 and $long2 are empty. When I print_r $mysongs, it says that the API key is wrong, which it isn't, and it returns a 403 error.

I'm pretty sure that this is a problem in the way I sent the URI in $mysongs, (cause I've had a similar problem before with the same API), but I'm not quite sure where.

The request I'm doing is ?q=19540 Jamboree Rd Ste 200 Irvine, CA&lat=33.852471&long=-117.7325256 .

Thanks you so much!

4

1 回答 1

1

This tested out perfectly for me. Maybe start with this as a basis and build up from there. http://www.laprbass.com/RAY_temp_solene.php

<?php // RAY_temp_solene.php
error_reporting(E_ALL);
echo "<pre>";


// API KEYS
require_once('api.php');

// REQUEST VARIABLES SIMULATED HERE
$qadr = urlencode('19540 Jamboree Rd Ste 200 Irvine, CA');
$qlat = 33.852471;
$qlng = -117.7325256;

// CALL THE MAPQUEST SERVICE
$mysongs = simplexml_load_file('http://www.mapquestapi.com/geocoding/v1/address?key=' . MAPQUEST_API . '&location=' . $qadr . '&callback=renderGeocode&format=xml');

// SHOW THE RESPONSE
var_dump($mysongs);

// ISOLATE THE GEOCODE OF THE RESPONSE
$lat = (string)$mysongs->results->result->locations->location->latLng->lat;
$lng = (string)$mysongs->results->result->locations->location->latLng->lng;

// DO SOMETHING ELSE
$mysongs4 = simplexml_load_file('http://www.mapquestapi.com/directions/v1/route?key=' . MAPQUEST_API . '&from=' . $qlat . ',' . $qlng . '&to=' . $lat . ',' . $lng . '&callback=renderNarrative&outFormat=xml');

// SHOW THE RESPONSE
var_dump($mysongs4);

$vari = $mysongs4->route[0]->time;
$vari = $vari / 60;

// THE FINAL DATA WE WANT TO FIND
echo '<h1>';
echo round($vari);
echo '</h1>';
于 2012-12-28T19:59:48.570 回答