Jack Y
Jack Y

Reputation: 95

what is placemark in flutter geocoding

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);
}

}

Upvotes: 0

Views: 3526

Answers (2)

dylan
dylan

Reputation: 349

Placemark() class helps you to get certain information like city name, country name, local code based on google map api. Before you use Placemark() in your app, you need to get decoded string info from google map api

https://maps.googleapis.com/maps/api/geocode/json?latlng='.$request->lat.','.$request->lng.'&key='."your api key here"

From your server side code should return json response and then

_placeMark = Placemark(name: _address)

Now _placeMark would help you get access to city, country, local code etc. For more go there https://www.dbestech.com/tutorials/flutter-google-map-geocoding-and-geolocator

Upvotes: 0

Nelson Jr.
Nelson Jr.

Reputation: 1207

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.

Upvotes: 2

Related Questions