flutter_geocoder icon indicating copy to clipboard operation
flutter_geocoder copied to clipboard

PlatformException when calling Geocoder.local.findAddressesFromQuery

Open stevenosse opened this issue 4 years ago • 43 comments

Hello everybody! I regularly use this plugin for building production applications; but i've recently been notified by a customer of a bug on an app, [...], below is the error shown in the console

E/flutter (12189): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(failed, Failed, null)
[38;5;244mE/flutter (12189): #0      StandardMethodCodec.decodeEnvelope[39;49m
[38;5;244mE/flutter (12189): #1      MethodChannel.invokeMethod[39;49m
E/flutter (12189): <asynchronous suspension>
[38;5;248mE/flutter (12189): #2      LocalGeocoding.findAddressesFromQuery[39;49m
E/flutter (12189): <asynchronous suspension>
[38;5;248mE/flutter (12189): #3      HomePageState.searchByLocality[39;49m
E/flutter (12189): <asynchronous suspension>
[38;5;248mE/flutter (12189): #4      HomePageState.build.<anonymous closure>.<anonymous closure>[39;49m
E/flutter (12189): <asynchronous suspension>
[38;5;244mE/flutter (12189): #5      _InkResponseState._handleTap[39;49m
[38;5;244mE/flutter (12189): #6      _InkResponseState.build.<anonymous closure>[39;49m
[38;5;244mE/flutter (12189): #7      GestureRecognizer.invokeCallback[39;49m
[38;5;244mE/flutter (12189): #8      TapGestureRecognizer._checkUp[39;49m
[38;5;244mE/flutter (12189): #9      TapGestureRecognizer.acceptGesture[39;49m
[38;5;244mE/flutter (12189): #10     GestureArenaManager.sweep[39;49m
[38;5;244mE/flutter (12189): #11     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent[39;49m
[38;5;244mE/flutter (12189): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent[39;49m
[38;5;244mE/flutter (12189): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent[39;49m
[38;5;244mE/flutter (12189): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue[39;49m
[38;5;244mE/flutter (12189): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket[39;49m
[38;5;244mE/flutter (12189): #16     _rootRunUnary  (dart:async/zone.dart:1136:13)[39;49m
[38;5;244mE/flutter (12189): #17     _CustomZone.runUnary  (dart:async/zone.dart:1029:19)[39;49m
[38;5;244mE/flutter (12189): #18     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:931:7)[39;49m
[38;5;244mE/flutter (12189): #19     _invoke1  (dart:ui/hooks.dart:250:10)[39;49m
[38;5;244mE/flutter (12189): #20     _dispatchPointerDataPacket  (dart:ui/hooks.dart:159:5)[39;49m

stevenosse avatar Aug 19 '19 12:08 stevenosse

@aloisdeniel Do you have any updates on this? We are trying to use this package on a production app and we would like to avoid using google api for this.

biklas7 avatar Aug 22 '19 09:08 biklas7

Unfortunately I didn't have encounterd this issue yet ...

It may be linked to the system, on what device model did this happened ?

I suppose that you checked the user permission, right ?

aloisdeniel avatar Aug 22 '19 10:08 aloisdeniel

I'm testing this on a Pixel 2. The app has location permissions. Do I need more permissions?

biklas7 avatar Aug 22 '19 11:08 biklas7

The weird thing is that it worked fine earlier... But it started crashing for no reason.. I was obliged to switch to bing geocoding

stevenosse avatar Aug 22 '19 11:08 stevenosse

I'm also using open street maps which is not ideal, but it works.

biklas7 avatar Aug 22 '19 11:08 biklas7

This is the error I'm getting:

Unhandled Exception: PlatformException(Error 10, kCLErrorDomain, A operação não pôde ser concluída. (kCLErrorDomain erro 10.))
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
<asynchronous suspension>
#2      LocalGeocoding.findAddressesFromCoordinates (package:geocoder/services/local.dart:13:41)

Don't know if it is related but I am querying multiple addresses at the same time, asynchonously.

shinayser avatar Sep 02 '19 18:09 shinayser

Capture1 I want to convert latitude and longitude to formatted address. I worked with it before and it worked nicely.But don't know why it shows me this error now.

bijoya-banik avatar Sep 03 '19 05:09 bijoya-banik

@aloisdeniel I found how to reproduce the bug.

Using this coordinate works well : (43.184319, 5.324419) Using this throws exception : (49.822816, -0.266805)

Unhandled Exception: PlatformException(not_available, Empty, null)

Seems like it does not accept negative lat/long

I though the bug was random at first because I was receiving differents GPS lat/lon from my server. Then I notice that some works and others doesn't.

g-balas avatar Sep 12 '19 12:09 g-balas

Hi! any updates on this issue? Because right-now the plugin is unusable...

SebastienBtr avatar Sep 23 '19 09:09 SebastienBtr

Hi guys. I am encountering this error too since this afternoon. It was working totally fine until one hour ago. I am using an emulator for a Pixel 2 on Ubuntu. However I tried on my real phone (Pixel) and here no error! So I updated everything and it's working on the emulator again! Hope this help someone!

arib7701 avatar Oct 19 '19 14:10 arib7701

Capture1 I want to convert latitude and longitude to formatted address. I worked with it before and it worked nicely.But don't know why it shows me this error now.

got the same issue, any progress?

foxineo avatar Oct 21 '19 07:10 foxineo

Same error is happening in iOS when using findAddressesFromQuery.

PlatformException(Error 8, kCLErrorDomain, The operation couldn’t be completed. (kCLErrorDomain error 8.))

This will happens only in some queries.

var address= awaitGeocoder.local.findAddressesFromQuery(desc);

How to solve this issue.

fazil-augr avatar Oct 22 '19 13:10 fazil-augr

Same error is happening in iOS when using findAddressesFromQuery.

PlatformException(Error 8, kCLErrorDomain, The operation couldn’t be completed. (kCLErrorDomain error 8.))

This will happens only in some queries.

var address= awaitGeocoder.local.findAddressesFromQuery(desc);

How to solve this issue.

I just give up, and use the other plugin amap_location, it works fine.

foxineo avatar Oct 23 '19 02:10 foxineo

@aloisdeniel Any news ?

g-balas avatar Nov 04 '19 16:11 g-balas

I found the issue it happening in iOS only. Because IOS using apple map not google map. The only way is use Google API for retrieving details.

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input={keyword}&inputtype=textquery&fields=geometry&key={API_KEY}

fazil-augr avatar Nov 05 '19 10:11 fazil-augr

I got error 10 by call Geocoder.local.findAddressesFromCoordinates, I found this error only happen on IOS .Every app started first call will work but If you call second time immediately will get this error.This happen to my app cuz for some reason I put Geocoder.local.findAddressesFromCoordinates in widget build function and somehow this widget rebuild immediately after first build.

ASE55471 avatar Nov 10 '19 18:11 ASE55471

Sorry for not being very active lately.

I'm not sure if all of you have the exact same issue (you got different codes, and you have different OS).

In the meantime, as a workaround you can use the Google distant api via Geocoder.google instead of Geocoder.local (you will need an API key). This is an equivalent solution of @fazil-augr proposal.

@g-balas Thank you for finding it! I will see if I can reproduce.

@ClassSadStranger Triggering asynchronous calls from the build method is not recommended because it can be called multiple times in a row! You should store the Future in a StatefullWidget instead.

aloisdeniel avatar Nov 22 '19 08:11 aloisdeniel

Moving to https://pub.dev/packages/geolocator

g-balas avatar Dec 12 '19 10:12 g-balas

geolocator has the same problem

AresVampire avatar Dec 18 '19 17:12 AresVampire

I had the same problem while using the emulator. But while using device, I dont have any problem.

I solved the emulator problem by opening the google maps and then running the app in emulator.

hope this helps some one from stop spending a lot of time like i did.

DennisSamul avatar Dec 31 '19 03:12 DennisSamul

Happened to have the same problem. In my case it was due to the fact that I was sending too many requests in a short time. The requests were sent using the "onChanged" event of a TextField.

I solved the problem by using a Timer to send one single request 1 second after the user has stopped typing.

Murys avatar Jan 07 '20 18:01 Murys

I had the same problem while using the emulator. But while using device, I dont have any problem.

I solved the emulator problem by opening the google maps and then running the app in emulator.

hope this helps some one from stop spending a lot of time like i did.

this worked for me in an emulator aswell, weirdly

lem-onade avatar Jan 16 '20 23:01 lem-onade

I am facing the same problem , I have a collection with list of document and each document has a field type of Geopoint , some of them work fine and translate the latitude and longitude to address , but some of them , gime me this error PlatformException(failed, Failed, null) .. and I set a value for these fields , I don't know why

sunaarun avatar Feb 25 '20 17:02 sunaarun

I have also faced the same problem on my emulator and my physical device

Aminsteir avatar Mar 31 '20 20:03 Aminsteir

I am also having the same problem but I realized that this error occurs when you are using Geocoder without internet. The problem is even if you put the code in try catch, it still raise the error

irchriscott avatar Jun 23 '20 17:06 irchriscott

For me the first call of Geocoder.local.findAddressesFromCoordinates(coordinates); is succesful, but then stop working.

In my case i have a page with a google map that shows the address every time the user stop move the map. When I open the page the address where the map is centered is retrieved correctly, then it throws the PlatformException(failed, Failed, null) at every later call.

It's strange that when i wrote the code everything worked well, then I closed the app and the emulator, relaunched it, and this error showed up

Ciock avatar Jul 16 '20 14:07 Ciock

Worked for me

Geocoder.google("APIKEY").findAddressesFromCoordinates(coordinates);

buraktuntas avatar Jul 19 '20 15:07 buraktuntas

that works because it is using google's API. This issue is related to calling the Geocoder local method.

"You can alternatively use Geocoder.google member for requesting distant data from google services instead of native ones." - https://pub.dev/packages/geocoder

On Sun, Jul 19, 2020 at 11:55 AM Burak Tuntaş [email protected] wrote:

Worked for me

Geocoder.google("APIKEY").findAddressesFromCoordinates(coordinates);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aloisdeniel/flutter_geocoder/issues/29#issuecomment-660667301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGB2YPH76MGHPCCRBCSVE4LR4MJQPANCNFSM4INARKCA .

Aminsteir avatar Jul 19 '20 17:07 Aminsteir

Guys. Same Error came for me in "GeoCoder" lib in android emulator. Set the default location in emulator settings. Then it will work fine.

BalaDhruv avatar Aug 06 '20 17:08 BalaDhruv

@stevenosse @aloisdeniel Hi guys! I have fixed it, please check https://github.com/aloisdeniel/flutter_geocoder/pull/47

otopba avatar Sep 01 '20 22:09 otopba