Question

So, I'm trying to pair Google and MapQuest's geocoding abilities because some address aren't able to be geocoded through Google, but they show up on Mapquest so I want to pair them. I was able to get the google results:

$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat1 = $output->results[0]->geometry->location->lat;
$lon1 = $output->results[0]->geometry->location->lng;

How do I get the results using MapQuest? I've never used MapQuest so I have no idea how it returns the data and I haven't found anything on here or anywhere that demonstrates retrieving the data...

HELP! Thanks!

Was it helpful?

Solution

You can use Jay Sheth's sample code then get latitude and longitude:

$json = file_get_contents('http://open.mapquestapi.com/geocoding/v1/address?key={your_key_here}&location=Lancaster,PA');
$jsonArr = json_decode($json);

$lat1 = $jsonArr->results[0]->locations[0]->latLng->lat;
$lon1 = $jsonArr->results[0]->locations[0]->latLng->lng;

OTHER TIPS

this code should start you off:

<?php
//Important: do not pass the callback=xyz parameter (as stated in the docs)
$json = file_get_contents('http://open.mapquestapi.com/geocoding/v1/address?key={your_key_here}&location=Lancaster,PA');
$jsonArr = json_decode($json);
print_r($jsonArr);
//Access latitude, longitude, etc. from PHP standard object
?>

More info: http://open.mapquestapi.com/geocoding/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top