Error while running Geocoder.local.findAddressesFromQuery

913 views Asked by At

I'm trying to get the coordinations of a String address using Geocoder, my code is working well on ios devices but when I run it on Android it shows me this error

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)

Here is my code

   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'),
    );

The place autocomplete is working well and returning the required address.

2

There are 2 answers

0
Rami Osman On BEST ANSWER

The problem seems to be related to the configuration of the emulator, when I tried the same program on another emulator it worked very well, I have tried to delete the emulator and install it again and the problem is solved !

1
Islomkhuja Akhrarov On

There can be many reasons of appearing this issue,

  1. Negative Lat or lang
  2. In emulator, it can throw exception while in real device not
  3. Problem with api
  4. Some people recommend to use Geocoder.google instead of Geocoder.local [Link for discussion this problem in github][1]