У меня проблемы с получением данных из объекта JSON, который я преобразовал в массив:
Это мой класс:
class tbfe_json_api {
var $location;
var $latitude;
var $longitude;
var $searchRadius = 20; // Default to 20 Miles
var $reverseGeoCodeJSON;
public function __construct() {
$this->getLocationParams();
$this->getCoords( $this->reverseGeoCodeLocation( $this->location ) );
}
public function getLocationParams() {
if( isset( $_GET['location'] ) ) {
$this->location = str_replace(' ', '' , $_GET['location'] );
if( isset( $_GET['radius'] ) ) {
$this->searchRadius = $_GET['radius'];
}
}
else {
die('Invalid parameters specified for JSON request.');
}
}
public function reverseGeoCodeLocation($location) {
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, 'http://maps.google.com/maps/geo?q='.$location.'&output=json');
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
return $this->reverseGeoCodeJSON = curl_exec($cURL);
curl_close ($cURL);
}
public function getCoords($json_data) {
$obj = json_decode($json_data, true);
var_dump($obj);
// I NEED THE COORDINATE VALUES HERE TO PLACE BELOW
$this->latitude = '';
$this->longitude = '';
}
}
И это тот массив, из которого мне нужно работать:
http://www.thebigfishexperience.org.uk/sources/ajax/venue-json.php?location=london
Мне нужно извлечь значения координат из массива и поместить их в переменные моего экземпляра, как показано выше.