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!

6
  • 1
    403 means Forbidden. May be you need to authenticate first. Commented Dec 28, 2012 at 19:53
  • 1
    @shiplu.mokadd.im In the MapQuest API, you authenticate via API key. As I said in my post, the API key is correct. I'm sure of that. "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." Commented Dec 28, 2012 at 20:01
  • Please show us the contents of the request variables (URL parameters) that you are using, thanks. Oh wait, nevermind - I see that in the question now! Commented Dec 28, 2012 at 20:07
  • 1
    @RayPaseur I posted in my original post "?q=19540 Jamboree Rd Ste 200 Irvine, CA&lat=33.852471&long=-117.7325256". Commented Dec 28, 2012 at 20:08
  • 1
    @RayPaseur Tried that, still didn't work. :( Commented Dec 28, 2012 at 20:12

1 Answer 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>'; 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks so much for the post, though I'd like to know excatly what I did incorrectly..
I don't know. I don't think in terms of code -- I think in terms of the data. When I can see the data I almost always find that the code writes itself. I'm just not smart enough to debug anyone else's code; my own code is a full challenge. My guess, and it's only a guess, is that the URL needed urlencode()
Ah yes! I found it! I to use $_GET, I had to do urlencode for all of them! Sorry about that... Thanks so much!!! :)
Yes, PHP automatically decodes the URL before loading it into $_GET