gpt4 book ai didi

android - 方法 'placemarkFromCoordinates' 没有为类型 'Geolocator' 定义

转载 作者:行者123 更新时间:2023-12-04 23:43:50 27 4
gpt4 key购买 nike

我正在尝试通过使用地标在我的 flutter 应用程序中获取用户位置。
我已经导入了运行应用程序所需的所有必要依赖项,但我仍然在地理定位器地标中遇到错误。我不知道该怎么办。

`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
请帮忙!!!

最佳答案

从版本 6.0.0 开始,地标已从 geolocator 中删除并移至 geocoding .
将地理编码导入文件后使用

List<Placemark> placemarks = await placemarkFromCoordinates(position.latitude, position.longitude);

关于android - 方法 'placemarkFromCoordinates' 没有为类型 'Geolocator' 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64967048/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com