运行 Geocoder.local.findAddressesFromQuery 时出错
Error while running Geocoder.local.findAddressesFromQuery
我正在尝试使用 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'),
);
地点自动完成功能正常并返回所需地址。
出现这个问题的原因有很多,
- 负纬度或 lang
- 在模拟器中,它可以抛出异常,而在真实设备中则不会
- api
有问题
- 有些人建议使用 Geocoder.google 而不是 Geocoder.local
[Link for discussion this problem in github][1]
问题似乎与模拟器的配置有关,当我在另一个模拟器上尝试相同的程序时它运行得很好,我尝试删除模拟器并重新安装,问题解决了!
我正在尝试使用 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'),
);
地点自动完成功能正常并返回所需地址。
出现这个问题的原因有很多,
- 负纬度或 lang
- 在模拟器中,它可以抛出异常,而在真实设备中则不会
- api 有问题
- 有些人建议使用 Geocoder.google 而不是 Geocoder.local
[Link for discussion this problem in github][1]
问题似乎与模拟器的配置有关,当我在另一个模拟器上尝试相同的程序时它运行得很好,我尝试删除模拟器并重新安装,问题解决了!