I'm wanting to reverse geocode coordinate to get the address using Geocoder-php. I'm able to get the Address Collection using $geo = app('geocoder')->reverse($lat, $lng)->get()
.
According to these docs found on github for Geocoder-php you can retrieve the properties form the collection, such as street name by using $geo->getStreetName()
, the city by using $geo->getCity()
, the country by using $geo->getCountry()
, etc, but there are no methods for returning the State or Province.
How do I grab the state or province from the collection?
I can see the province when I use $geo->getAdminLevels()->get()
. Which returns
AdminLevelCollection {#900 ▼
-adminLevels: array:2 [▼
1 => AdminLevel {#901 ▼
-level: 1
-name: "Saskatchewan"
-code: "SK"
}
2 => AdminLevel {#902 ▼
-level: 2
-name: "Division No. 16"
-code: "Division No. 16"
}
]
}
But I am unable to grab the province (Saskatchewan).
(I am using Laravel Geocoder for a Laravel project.)
EDIT:
$geo->getAdminLevels()->get(1)
give me this
AdminLevel {#690 ▼
-level: 1
-name: "Saskatchewan"
-code: "SK"
}
But $geo->getAdminLevels()->get(1)->name;
give me this error
Undefined property: Geocoder\Provider\GoogleMaps\Model\GoogleAddress::$getAdminLevels