<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>
我做错了什么? 变量$ lat2和$ long2为空。当我print_r $ mysongs时,它表示API密钥是错误的,它不是,它返回403错误。
我很确定这是我在$ mysongs中发送URI的方式存在问题,(因为我在使用相同的API之前遇到了类似的问题),但我不确定在哪里。< / p>
我正在做的请求是?q = 19540 Jamboree Rd Ste 200 Irvine,CA&amp; lat = 33.852471&amp; long = -117.7325256。
非常感谢你!
答案 0 :(得分:1)
这对我来说非常适合。也许从这开始作为基础并从那里积累起来。 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>';