运行 Geocoder.local.findAddressesFromQuery 时出错
Posted
技术标签:
【中文标题】运行 Geocoder.local.findAddressesFromQuery 时出错【英文标题】:Error while running Geocoder.local.findAddressesFromQuery 【发布时间】:2021-02-01 12:43:27 【问题描述】:我正在尝试使用 Geocoder 获取字符串地址的协调,我的代码在 ios 设备上运行良好,但是当我在 android 上运行它时,它显示了这个错误
I/zygote (29355): Do partial code cache collection, code=58KB, data=46KB
I/zygote (29355): After code cache collection, code=57KB, data=46KB
I/zygote (29355): Increasing code cache capacity to 256KB
E/flutter (29355): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(failed, Failed, null)
E/flutter (29355): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:572:7)
E/flutter (29355): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:161:18)
E/flutter (29355): <asynchronous suspension>
E/flutter (29355): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
E/flutter (29355): #3 LocalGeocoding.findAddressesFromQuery (package:geocoder/services/local.dart:18:43)
E/flutter (29355): #4 _TextFieldAutoCompleteState.build.<anonymous closure> (package:label_national_h/Widgets/TextFieldAutoComplete.dart:33:46)
E/flutter (29355): <asynchronous suspension>
E/flutter (29355): #5 _TextFieldAutoCompleteState.build.<anonymous closure> (package:label_national_h/Widgets/TextFieldAutoComplete.dart)
E/flutter (29355): #6 _TextFieldSelectionGestureDetectorBuilder.onSingleTapUp (package:flutter/src/material/text_field.dart:107:26)
E/flutter (29355): #7 _TextSelectionGestureDetectorState._handleTapUp (package:flutter/src/widgets/text_selection.dart:1298:29)
E/flutter (29355): #8 TapGestureRecognizer.handleTapUp.<anonymous closure> (package:flutter/src/gestures/tap.dart:522:56)
E/flutter (29355): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
E/flutter (29355): #10 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:522:11)
E/flutter (29355): #11 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
E/flutter (29355): #12 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:256:7)
E/flutter (29355): #13 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:158:27)
E/flutter (29355): #14 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:224:20)
E/flutter (29355): #15 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
E/flutter (29355): #16 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
E/flutter (29355): #17 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
E/flutter (29355): #18 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
E/flutter (29355): #19 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (29355): #20 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (29355): #21 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (29355): #22 _invoke1 (dart:ui/hooks.dart:267:10)
E/flutter (29355): #23 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
这是我的代码
return TextField(
controller: textEditController,
onTap: () async
p = await PlacesAutocomplete.show(
context: context,
apiKey: R.Google_api_key,
language: "fr",
components: [Component(Component.country, "fr")]);
textEditController.text = p.description;
var addresses = await Geocoder.local.findAddressesFromQuery(p.description);
schedule.UpdateListeners(addresses.first.coordinates.latitude,addresses.first.coordinates.longitude) ;
//final double distance = await distanceBetween( addresses.first.coordinates.latitude, addresses.first.coordinates.longitude, endLatitude, endLongitude);
,
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Adresse, ex. 5 Rue Thénard Paris'),
);
地点自动完成功能运行良好并返回所需地址。
【问题讨论】:
【参考方案1】:出现这个问题的原因有很多,
-
负纬度或语言
在模拟器中会抛出异常,而在真实设备中则不会
api 问题
有些人建议使用 Geocoder.google 而不是 Geocoder.local
[Link for discussion this problem in github][1]
【讨论】:
您好 Akhrarov,感谢您的帮助,但您的解决方案都没有帮助,问题似乎与网络问题有关,我重新配置了我的模拟器,它可以工作了!【参考方案2】:这个问题好像和模拟器的配置有关,我在另一个模拟器上试了同样的程序,效果很好,我试过删除模拟器重新安装,问题就解决了!
【讨论】:
以上是关于运行 Geocoder.local.findAddressesFromQuery 时出错的主要内容,如果未能解决你的问题,请参考以下文章