I'm getting google response in json format. when I decode and print the output it works perfectly. Like this-> print_r($output);
But when I trying to access the single parameter of the array it's not working. print_r($output->results[0]->geometry->location->lat); It gives this error. "message": "Undefined offset: 0",
public function mapdata(Request $request){
$address = $request->name;
$formattedAddress = str_replace(' ','+',$address);
$response = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddress.'&sensor=true_or_false&key=AIzaSyC8retyF0d5v2jP-H6fdffd-og');
$output = json_decode($response);
//print_r($output);
print_r($output->results[0]->geometry->location->lat);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire