So I have this data wich is returned from a request and then decoded with json_decode, I wish to access the city and postcode values from it. But my knowledge of php is very limited, and I can't seem to access them via -> operator or ['properties']. Am I doing something wrong, or is this supposed to be accessed via a for each? Or via a numerical index?
public function getGeoData($latitude, $longitude) {
$lat = strval(number_format((float)$latitude, 5, '.', ''));
$lon = strval(number_format((float)$longitude, 5, '.', ''));
$response = Http::get('https://nominatim.openstreetmap.org/reverse?format=geojson&lat=' . $lat . '&lon=' . $lon);
return json_decode($response);
}
returned data:
[
{
"type": "Feature",
"properties": {
"place_id": 27241982,
"osm_type": "way",
"osm_id": 103870558,
"place_rank": 30,
"category": "place",
"type": "house",
"importance": -0.1,
"addresstype": "place",
"name": null,
"display_name": "543, Rue de la Reine, District03, Saint-Roch, La Cité-Limoilou, Québec, Québec (Agglomération), Capitale-Nationale, Québec, G1K 6A2, Canada",
"address": {
"house_number": "543",
"road": "Rue de la Reine",
"residential": "District03",
"suburb": "Saint-Roch",
"city_district": "La Cité-Limoilou",
"city": "Québec",
"county": "Québec (Agglomération)",
"region": "Capitale-Nationale",
"state": "Québec",
"ISO3166-2-lvl4": "CA-QC",
"postcode": "G1K 6A2",
"country": "Canada",
"country_code": "ca"
}
},
"bbox": [
-71.223775242105,
46.816099889474,
-71.223675242105,
46.816199889474
],
"geometry": {
"type": "Point",
"coordinates": [
-71.22372524210526,
46.816149889473685
]
}
}
]