【问题标题】:what is placemark in flutter geocoding颤动地理编码中的地标是什么
【发布时间】:2022-11-18 09:27:11
【问题描述】:

我是 flutter google maps 的初学者。我只想知道 flutter geocoding 中的地标是什么,我只需要了解下面的代码。非常感谢您的帮助。

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

}

【问题讨论】:

    标签: flutter google-maps geocoding google-maps-api-2


    【解决方案1】:

    Placemark 是一个包含地名、地点、邮政编码、国家和其他属性等信息的类。请参阅文档中的属性。

    placemarkFromCoordinates 是一种返回为提供的坐标找到的 Placemark 实例列表的方法。

    Placemark place = p[0] 只是从您从 placemarkFromCoordinates 方法获得的列表中获取第一个地标。

    setState 方法中的代码只是将 _currentAddress 更新为您从地标 place 获得的地点信息,然后将其值传递给 startAddressController.text_startAddress

    【讨论】:

      【解决方案2】:

      Placemark() 类可帮助您获取某些信息,如城市名称、国家名称、基于 google map api 的本地代码。 在您的应用程序中使用 Placemark() 之前,您需要从 google map api 获取解码的字符串信息

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

      从你的服务器端代码应该返回 json 响应然后

      _placeMark = Placemark(name: _address)
      

      现在 _placeMark 将帮助您访问城市、国家、本地代码等。 更多去那里 https://www.dbestech.com/tutorials/flutter-google-map-geocoding-and-geolocator

      【讨论】:

        猜你喜欢
        • 2021-12-03
        • 1970-01-01
        • 2011-10-16
        • 2020-06-11
        • 2020-05-09
        • 1970-01-01
        • 1970-01-01
        • 2016-03-05
        • 2013-09-28
        相关资源
        最近更新 更多