从JSON获取数据(使用Mapquest和PHP)

use*_*118 3 php json mapquest

因此,我正在尝试配对Google和MapQuest的地理编码功能,因为某些地址无法通过Google进行地理编码,但它们会显示在Mapquest上,因此我想将它们配对.我能够得到谷歌的结果:

$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;
Run Code Online (Sandbox Code Playgroud)

如何使用MapQuest获得结果?我从来没有使用过MapQuest,所以我不知道它是如何返回数据的,我在这里或任何地方都找不到任何可以显示检索数据的东西......

救命!谢谢!

dom*_*omi 7

您可以使用Jay Sheth的示例代码然后获取纬度和经度:

$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;
Run Code Online (Sandbox Code Playgroud)