没有为“地理定位器”类型定义方法“placemarkFromCoordinates”
Posted
技术标签:
【中文标题】没有为“地理定位器”类型定义方法“placemarkFromCoordinates”【英文标题】:The method 'placemarkFromCoordinates' isn't defined for the type 'Geolocator' 【发布时间】:2021-03-06 02:05:53 【问题描述】:我正在尝试使用地标在我的颤振应用中获取用户位置。 我已经导入了运行应用程序所需的所有必要依赖项,但我仍然在地理定位器地标中遇到错误。我不知道该怎么办。
`import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:ft06/requests/google_maps_requests.dart';
class AppState with ChangeNotifier
static LatLng _initialPosition;
LatLng _lastPosition = _initialPosition;
bool locationServiceActive = true;
final Set<Marker> _markers = ;
final Set<Polyline> _polyLines = ;
GoogleMapController _mapController;
GoogleMapsServices _googleMapsServices =
GoogleMapsServices();
TextEditingController locationController =
TextEditingController();
TextEditingController destinationController =
TextEditingController();
LatLng get initialPosition => _initialPosition;
LatLng get lastPosition => _lastPosition;
GoogleMapsServices get googleMapsServices =>
_googleMapsServices;
GoogleMapController get mapController =>
_mapController;
Set<Marker> get markers => _markers;
Set<Polyline> get polyLines => _polyLines;
AppState()
_getUserLocation();
_loadingInitialPosition();
// ! TO GET THE USERS LOCATION
void _getUserLocation() async
print("GET USER METHOD RUNNING =========");
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy:LocationAccuracy.high);
List<Placemark> placemark = await Geolocator()
.placemarkFromCoordinates(position.latitude,
position.longitude);
_initialPosition = LatLng(position.latitude,
position.longitude);
print("the latitude is: $position.longitude
and th longitude is: $position.longitude ");
print("initial position is :
$_initialPosition.toString()");locationController.
text = placemark[0].name;
notifyListeners();
actual error output terminal
请帮忙!!!
【问题讨论】:
【参考方案1】:从版本 6.0.0 开始,地标已从 geolocator 中删除并移至 geocoding。
将地理编码导入文件后使用
List<Placemark> placemarks = await placemarkFromCoordinates(position.latitude, position.longitude);
【讨论】:
以上是关于没有为“地理定位器”类型定义方法“placemarkFromCoordinates”的主要内容,如果未能解决你的问题,请参考以下文章