I m very beginner for flutter google maps. I just want to know what is placemark in flutter geocoding and I just need to understand the below code. Thank you so much for any help.
_getAddress() async {
try {
List<Placemark> p = await placemarkFromCoordinates(
_currentPosition.latitude, _currentPosition.longitude);
Placemark place = p[0];
setState(() {
_currentAddress =
"${place.name}, ${place.locality}, ${place.postalCode}, ${place.country}";
startAddressController.text = _currentAddress;
_startAddress = _currentAddress;
});
} catch (e) {
print(e);
}
}
CodePudding user response:
Placemark is a class that contains information like place's name, locality, postalCode, country and other properties. See Properties in the documentation.
placemarkFromCoordinates is a method that returns a list of Placemark instances found for the supplied coordinates.
Placemark place = p[0]
just gets the first Placemark from the list you got from placemarkFromCoordinates method.
The code inside the setState
method just updates the _currentAddress
to the place info you got from the Placemark place
and then passes its value to the startAddressController.text
and _startAddress
.