web-dev-qa-db-ja.com

Flutter - 座標からジオコードアドレスを取得します

私はユーザーLATを取得する信頼できる方法を実装しています。

このデータを印刷するために使用する必要があるものを理解したいのですが。

これは私がこのデータを取得しようとしているものです:

List<Placemark> place = [];

void _getPlace() async {
  List<Placemark> newPlace = await _geolocator.placemarkFromCoordinates(_position.latitude, _position.longitude);
  print(newPlace);
  setState(() {
    place = newPlace;
  });
}
 _

ありがとう

編集:

CopsonRoadの応答の後、このエラーが発生しています。

[VERBOSE-2:ui_Dart_state.cc(148)] Unhandled Exception: 

NoSuchMethodError: The method 'placemarkFromCoordinates' was called on null.
Receiver: null
Tried calling: placemarkFromCoordinates(51.4998, -0.129)
#0      Object.noSuchMethod  (Dart:core-patch/object_patch.Dart:50:5)
#1      _NearbyPageState._getPlace 
package:tr/pages/nearby.Dart:128
<asynchronous suspension>
#2      _NearbyPageState._controlCard.<anonymous closure> 
package:tr/pages/nearby.Dart:629
#3      GestureRecognizer.invokeCallback 
package:flutter/…/gestures/recognizer.Dart:182
#4      TapGestureRecognizer._checkUp 
package:flutter/…/gestures/tap.Dart:365
#5      TapGestureRecognizer.acceptGesture 
package:flutter/…/gestures/tap.Dart:312
#6      GestureArenaManager.sweep 
package:flutter/…/gestures/arena.Dart:156
#7      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent 
package:flutter/…/gestures/binding.Dart:222
#8      _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (p<…>
 _
6
Jake4142
 try {
    await Geolocator()
        .placemarkFromCoordinates(value[0], value[1])
        .then((result) {
      Placemark placeMark = result[0];
      String name = placeMark.name;
      String subLocality = placeMark.subLocality;
      String locality = placeMark.locality;
      String administrativeArea = placeMark.administrativeArea;
      String postalCode = placeMark.postalCode;
      String country = placeMark.country;
      String address =
          "${name}, ${subLocality}, ${locality}, ${administrativeArea} ${postalCode}, ${country}";
      print(address);
      
    });
  } on PlatformException catch (e) {
    print(e);
  }
 _
1
Muhammad Ashraf