' null'可以将可以分配给type;位置的变量'

发布于 2025-01-25 09:21:08 字数 3014 浏览 3 评论 0原文

我想使用“ Geolocator”软件包从用户那里获取地理位置数据。逻辑是这样的,当我收到地理位置时,我将其发送给控制器以获取Google Maps,并在一段时间后根据接收到的坐标将地图传输。我写了一个函数,但会引发一个错误:

类型“ null”的值无法分配给类型的变量 '位置'。尝试更改变量的类型,或施放 右手类型为“位置”。

显示的错误

Future<void> _getCurrentPosition() async {
Position position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
    .then((Position position) async {
  final GoogleMapController controller = await _controller.future;
  controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
      target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
  print(e);
});}

在此替换一部分函数后

Position? position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
    .then((Position position) async {
  final GoogleMapController controller = await _controller.future;
  controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
      target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
  print(e);
});}

发生了另一件事,当我在物理设备上运行应用程序时,调试器显示此消息:在1 796ms中重新启动应用程序。 2022-05-01 23:39:05.165 Runner [2516/0x102610580] [LVL = 3] +[GMSX_CCTCLEARCUTUPLOADER crastififneclastory]多个cctclearcutuploader的实例。多个上载器正常运行,但由于锁定争夺而对电池性能产生不利影响。 [tcp] tcp_input [c4.1:3] flags = [r] seq = 611763406,ack = 0,win = 0 state =确定的rcv_nxt = 611763406,snd_una,snd_una = 1878468883连接4:接收失败通知连接4:接收到econnnernesete connectect econnnernesetetementect TLS握手 - 生成errsslclosednotify连接4:无法连接3:-9816,原因-1连接4:遇到错误(3:-9816)任务&lt; d01e9b91-bb3f-4674-ab74-ab74-ab74-ab74-5063e63e63636262617&gt;&gt;&lt;&lt;&lt; HTTP负载失败,0/0字节(错误代码:-1200 [3:-9816])2 [TCP] TCP_INPUT [C4.1:3] flags = [r] seq = 611763406,ack = 0,ack = 0,win = 0 =闭合RCV_NXT = 611763406,SND_UNA = 1878468883任务&lt; d01E9B91-BB3F-4674-AB74-AB74-5063E6362617&gt;。完成错误[-1200]错误域= nsurlorrordomain code = -1200“已经发生了SSL错误,无法与服务器进行安全连接。” userInfo = {nserrorfailingurlstringkey = https://client4.google.com/glm/mmap,nslocalizedRecoverySuggeSuggestion =您是否想连接到服务器? 3F-4674-AB74-5063E6362617&GT ;.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalUploadTask.<1>" ), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made. ,nserrorfailingurlkey = https://client4.google.com/glm/mmap,nsunderlyingerror = 0x28150CA50 {错误域= kcferrordomaincfnetwork代码= -1200 slerRoriginalValue = -9816,_kcfstreamerordomainkey = 3, _KCFSTREAMERRORCODEKEY = -9816,_nSurlerrRornWpathKey =满意(满足路径),可行,接口:utun2,ipv4,dns,昂贵}},_kcffstreamerorcodekey = -9816} = 611763406,ack = 0,win = 0状态=闭合RCV_NXT = 611763406,SND_UNA = 1878468883 -CANOPENURL:url for url:“ comgooglemaps:/comgooglemaps://” :失败的URL:“ GoogleChromes://” - 错误:“此应用不允许查询方案GoogleChromes“丢失与设备的连接。

是什么,这是什么重要的?多谢!

I want to get geolocation data from the user using the "geolocator" package. The logic is such that when I receive a geolocation, I send it to the controller for Google Maps and after some time the map transfers according to the received coordinates. I wrote a function, but it throws an error :

A value of type 'Null' can't be assigned to a variable of type
'Position'. Try changing the type of the variable, or casting the
right-hand type to 'Position'.

The error showing there

Future<void> _getCurrentPosition() async {
Position position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
    .then((Position position) async {
  final GoogleMapController controller = await _controller.future;
  controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
      target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
  print(e);
});}

After replacing a part of function on this

Position? position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
    .then((Position position) async {
  final GoogleMapController controller = await _controller.future;
  controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
      target: LatLng(position.latitude, position.longitude), zoom: 14)));
}).catchError((e) {
  print(e);
});}

There comes another thing, when i run the app on physical device the debugger shows this messages:Restarted application in 1 796ms. 2022-05-01 23:39:05.165 Runner[2516/0x102610580] [lvl=3] +[GMSx_CCTClearcutUploader crashIfNecessary] Multiple instances of CCTClearcutUploader were instantiated. Multiple uploaders function correctly but have an adverse affect on battery performance due to lock contention. [tcp] tcp_input [C4.1:3] flags=[R] seq=611763406, ack=0, win=0 state=ESTABLISHED rcv_nxt=611763406, snd_una=1878468883 Connection 4: received failure notification Connection 4: received ECONNRESET with incomplete TLS handshake - generating errSSLClosedNoNotify Connection 4: failed to connect 3:-9816, reason -1 Connection 4: encountered error(3:-9816) Task <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9816]) 2 [tcp] tcp_input [C4.1:3] flags=[R] seq=611763406, ack=0, win=0 state=CLOSED rcv_nxt=611763406, snd_una=1878468883 Task <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://clients4.google.com/glm/mmap, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalUploadTask <D01E9B91-BB3F-4674-AB74-5063E6362617>.<1>" ), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://clients4.google.com/glm/mmap, NSUnderlyingError=0x28150ca50 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816, _NSURLErrorNWPathKey=satisfied (Path is satisfied), viable, interface: utun2, ipv4, dns, expensive}}, _kCFStreamErrorCodeKey=-9816} [tcp] tcp_input [C4.1:3] flags=[R] seq=611763406, ack=0, win=0 state=CLOSED rcv_nxt=611763406, snd_una=1878468883 -canOpenURL: failed for URL: "comgooglemaps://" - error: "This app is not allowed to query for scheme comgooglemaps" -canOpenURL: failed for URL: "googlechromes://" - error: "This app is not allowed to query for scheme googlechromes" Lost connection to device.

Whats is it and is this important? Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你曾走过我的故事 2025-02-01 09:21:08

try{
    Position position = await Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
        ..then((Position position) async {
      final GoogleMapController controller = await _controller.future;
      controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
          target: LatLng(position.latitude, position.longitude), zoom: 14)));
    }).catchError((e) {
      print(e);
    });}
}catch(e){}

Position? position = await Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
        .then((Position position) async {
      final GoogleMapController controller = await _controller.future;
      controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
          target: LatLng(position.latitude, position.longitude), zoom: 14)));
    }).catchError((e) {
      print(e);
    });}

Replace your code with

try{
    Position position = await Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
        ..then((Position position) async {
      final GoogleMapController controller = await _controller.future;
      controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
          target: LatLng(position.latitude, position.longitude), zoom: 14)));
    }).catchError((e) {
      print(e);
    });}
}catch(e){}

or

Position? position = await Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
        .then((Position position) async {
      final GoogleMapController controller = await _controller.future;
      controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
          target: LatLng(position.latitude, position.longitude), zoom: 14)));
    }).catchError((e) {
      print(e);
    });}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文