Geocoder getFromLocation failed - android

I'm trying to get placemarks from coordinates.
I'm using geoLocator for that. It was working fine today morning, but now, it throws platform exception.
PlatformException(IO_ERROR, A network error occurred trying to lookup the supplied coordinates (latitude: <lat>, longitude: <long>)., null)
It says it's a network error, but my device is connected to the internet,
First, i thought there might be some problem in the Geolocator package, so i used Geocoding package, but the problem persists.
This is the error from geocoder.
Geocoder getFromLocation --- mService = android.location.ILocationManager$Stub$Proxy#e8c2197, ex = grpc failed, return results = []
Please help.

Try to WIPE DATA on your emulator.
Restart it.
It works.

See this flutter_geocoding issue (closed): https://github.com/Baseflow/flutter-geocoding/issues/23
Two solutions presented:
create a new emulator
stop WiFi on the emulator, restart WiFi and let it find the network (AndroidWiFi)
Solution 2 worked for me.

try to add localeIdentifier parameter. works for me. my function code will be like
List<Placemark> newPlace = await GeocodingPlatform.instance.placemarkFromCoordinates(position.latitude, position.longitude,localeIdentifier: "en");

I had the same problem.
Try another emulator (create another emulator as if you are using another android or ios device).
May be the current device that is being emulated is having problems connecting to the internet

its mainly due to change in location of your device if you're using a external device like an android phone then you should reboot your device and it'll work .

I've faced the same issue.
Reason - The internet was not working inside my emulator.
Answer - If internet is not working inside your emulator, cold wipe your emulator from the virtual device manager and check again.
It solved my issue.

Not sure what is the problem, but I ended up making a new android emulator(a new emulated device) and it worked fine.

Related

How to solve SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)

Whenever I try to do an http call after about 20 seconds I get in the console the following error:
E/flutter ( 8274): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 8274): SocketException: Failed host lookup: 'flutter-project-xxxxx.firebaseio.com' (OS Error: No address associated with hostname, errno = 7)
This error happens for every method and every route I call through the app http package.
I'm developing a flutter app on Windows, using an AVD virtual device from Android Studio.
Versions:
http: ^0.12.0+1
flutter: 1.0
Cases:
From home or though tethering from my phone:
connectivity works fine on every part of the virtual device
From my work network (behind the firewall):
Only with Android Web View, I can browse the internet without any problem (i can even call the same url, I use in the code and it works).
I get a connection error when using any other application (Chrome, Google Play, ecc...) in the virtual device, and specifically the "SocketException", when testing my app.
What is the difference between the calls coming from that app?
Is there a way to route my app calls the same way as the ones in the webview?
Thanks!
Adding internet permission is not only a solution.
You also have to make sure that you are online whether it is mobile or emulator
Make sure you are online whether it is mobile or emulator
Make sure you have given internet permission in your app's android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Add <uses-permission android:name="android.permission.INTERNET" /> to your AndroidManifest.xml file.
I added <uses-permission android:name="android.permission.INTERNET" /> to
my manifest. I then had to restart the emulator for internet to work.
Make sure you have added the in android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
If you are using an emulator make sure that the mobile data is active
You should try following:
Try run application in debug mode if its working fine and not working in release mode then it might be related to permission issue so add permissions(INTERNET, ACCESS_NETWORK_STATE) in manifest file.
your_project_root_directory/android/app/src/debug/AndroidManifest.xml
your_project_root_directory/android/app/src/main/AndroidManifest.xml
your_project_root_directory/android/app/src/profile/AndroidManifest.xml
If not included then add permissions:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
If its not working in debug mode, then check either your url is correct by hitting in postman. If its working in postman then you should execute your webservice in this way:
Add dependency in pubspec.yaml:
dependencies:
flutter:
sdk: flutter
http: 0.13.3
After adding http:0.13.3 then click on Pub get button If its executed with code 0 then it means its successfully added to your project.
in your dart file import http.dart:
import 'package:http/http.dart';
Now write this code to execute webservice:
var url = Uri.parse('some-url-login?username=abc&&password=xyz');
var response = await get(url, headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods':
'GET,PUT,POST,DELETE'
});
if (response.statusCode == 200) {
// success
} else if(response.statusCode == 404){
// not found
} else if(response.statusCode == 500){
// server not responding.
} else {
// some other error or might be CORS policy error. you can add your url in CORS policy.
}
I hope it will help you. Chill!
Go for AVD manager, then choose your emulator, on Actions menu click down option sign, then choose wipe data, then restart your emulator. It works for me.
Even I had the same issue. I restarted my emulator and it worked!!
If you are getting this error while using the flutter_socket_io plugin, don't forget to initialize the socket i.e socketIO.init(); socketIO.connect(); before attempting to subscribe to it. I received the same error as that indicated above when I omitted it.
By enabling WIFI it works for me, and make sure you also added the internet permission in the android manifest it added automatically also but you have to make sure. if still not then invalidate caches and restart hope it works
In my case it was because my phone was not connected to internet
Just enable internet connexion
Make sure your Mobile device or Emulator is connected to the internet
In My case I opened the emulator before I connected to the WIFI to system.When network(WIFI) has connected to my system but unable to connect to emulator .
Due to no internet access to the Emulator,this issues occurs.I resolved this issues by this way.
Solutions:
Connected network access to the system then I Closed the emulator and re-open it. Install applications ,run application and open it .And Finally works every API works fine.
When i enabled wifi on my device, it worked fine.
Even after adding
<uses-permission android:name="android.permission.INTERNET"/>
in your android/app/src/main/AndroidManifest.xml, if you're still finding trouble then
There maybe an error with the website's server IP address like:
Server IP address could not be found
It's better to wait for some time and make sure to restart wifi, it worked for me.
Make sure your Emulator or your device connected to the internet.
if your Emulator could not connect to the internet use a VPN.
The problem for me was that I was using a VPN. The emulator didn't have internet access when connected to the VPN on my computer. It might help someone.
I'm using arch Linux.
Linux arch 5.14.7-arch1-1
And Flutter version
Flutter 2.2.1
Dart version
Dart 2.13.1
Code editor
1.58.0
In my case turning on wifi solved the problem.
Check if the wifi is connected or not. Mine worked after restarting the wifi.
Make sure the internet is on (both on the phone and the PC)
also, make sure the server is working properly
check your URL properly
Sometimes, other wifi can have interference with your connected wifi, which can cause this error as well. Try to set your connected wifi's channel to auto or away from other wifi's channels.
I had the same problem while running the app on an emulator.
My laptop was connected to the internet through my phone's mobile hotspot.
But apparently the emulator was unable to access the internet
Later, I switched to my Wi-Fi Router connection and the application proceeded smoothly as expected.
I'm not sure, but is there any special access to be granted?
Tip: Try googling something on the emulator to check internet connectivity
For me it was just bad url with function "Uri.https(...)" in Flutter.
Check if the address is correct with your browser
The DNS settings on my mac were invalid...just use 8.8.8.8 without any internal DNS routing addresses
The problem is basically coming when device is trying to access any internet resources,to fix add the
to AndroidManifest.xml file #android/app/src location.
Check if you have enabled offline work in the gradle settings.
File-> Settings -> Build -> Build Tools -> Offline work
If its enabled or checked then uncheck it.
Also, might good to look at the 'Proxy settings' inside the 'Extended controls' of the emulator.
The way it worked for me was to change to use the 'No Proxy' setting.
Double-check / make sure you have
<uses-permission android:name="android.permission.INTERNET" />
in your app's android/app/src/main/AndroidManifest.xml
if you're using vscode you would get gai_error=0 that's if the http is connected successfully
Here is the right place to place the internet permission because it was quite challenging to know the location
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appName">
<uses-permission android:name="android.permission.INTERNET" />
run the flutter run command on cmd or visual studio code terminal
I deliberately disconnected my emulator wifi to see what would happen (as there could be cases where no internet is available). The error led me here, but, all I see are workarounds and not error handling. Really, the app should be able to handle the error gracefully and not crash out because of a lack of connection.
So far, all I have done is to catch the error and if the return code is -1 (or anything other than a 200), I know I have a problem and can make the app respond appropriately.
var request = new http.MultipartRequest("POST", uri);
// multipart that takes file
var multipartFile = new http.MultipartFile('file', stream, length,
filename: fileToUpload.path);
// add file to multipart
request.files.add(multipartFile);
// send
try {
var response = await request.send();
print(response.statusCode);
// listen for response
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});
return response.statusCode;
}
catch (e)
{
return -1;
}

Geocoder.getFromLocation grpc failed on Android real device

I need to get the city and state from latitude and longitude. Geocoder does this function to get the city and state. But I am getting an error java.io.IOException: grpc failed in below line only on Android real device. It is working fine in emulators.
new Geocoder(context).getFromLocation(latLng.latitude, latLng.longitude, 1).get(0);
Also I have been calling this function using Asynctask which is suggested in another post Geocoder grpc failed in stack overflow but nothing works for me.
And I have restart the device as well but still it is failing.
Help needed here. Thanks in advance.
Note: I tested in Google Pixel XL, Samsung S6 edge, Samsung S4.
It looks like this is ongoing issue that was reported in the Google issue tracker both for real devices and emulators. You can refer to the following bugs:
https://issuetracker.google.com/issues/64418751
https://issuetracker.google.com/issues/64247769
Unfortunately, Google haven't solved these issues yet.
As a workaround you can consider using the Geocoding API web service. Please note that there is a Java client library for web services that you can find on Github:
https://github.com/googlemaps/google-maps-services-java
Using Java client library for web services you can implement reverse geocoding lookup that shouldn't give you the error that you experience with native Android geocoder.
The Javadoc for client library is located at
https://googlemaps.github.io/google-maps-services-java/v0.2.5/javadoc/
I hope this helps!
Check your internet connection .
what is going on is at some point between the search and the results rendering , the connection is either to slow or not working at all . so the default error is no GRCP found. your code needs to handle this type of errors and prevent the crash of the map
Happened for me both with a real and an emulated device. Solved my restarting the app after cleaning the project
For me, it was the device time. I was doing some tests, and I had to change the device time. The device time must be set correctly, otherwise you get this error.
It is a reported bug in Android, check #xomena answer for the link.
Alternately, you can use the web services. Add this to gradle dependencies:
api 'com.google.maps:google-maps-services:0.10.2'
Sample code to get addresses:
val geoApiCtx = GeoApiContext.Builder()
.apiKey(Util.readGoogleApiKey(ctx))
.build()
val addresses = GeocodingApi.reverseGeocode(geoApiCtx, loc).await()
When I run with emulator I got the same problem.
The problem has solved after i run with real device.
Making the call to fetch an address via geocoder is recommended to do via an IntentService....but if you're in rapid development mode and don't want to bother setting up a service just yet, you can use a try/catch block
example in Kotlin:
try{
val addressList = geocoder.getFromLocationName(locationName, 3)
//...
}catch(e: IOException) {
when{
e.message == "grpc failed" -> {/* display a Toast or Snackbar instead*/ }
else -> throw e
}
}
What I did was, I changed my accuracy to GPS only, in this case, the application was not calculating my location. I again changed the accuracy to high accuracy and the application started working, no crash at all. you can change your GPS accuracy from location setting on your android mobile.
Using an emulator. I had to update the Google Play Services on the device and then it worked!

When I try to send a location update to the emulator I get an error message

When I am in the emulator control view in the DDMS I am attempting to send a Mock Location to my emulator. However when I try this I get the following error message, "Unable to send command to the emulator". I cannot understand why this is not working as it was fine yesterday and I havent made any changes to my application. Please help?
I was facing same problem. After restarting process of adb.exe from task manager it worked.
If you use mobile device for checking results, I think in your code, you would have mentioned the NETWORK_PROVIDER in location manager. If it is, then change it to GPS_PROVIDER and dont forget to add the permissions in your manifest file(android.permission.ACCESS_FINE_LOCATION). And now send the command through emulator control. it will work.

UnknownHostException in android

When i run my application for
sometime, suddenly the network is getting disconnected and i am
getting the unknownhostexception in my application. In that case if i
check the browser, the same exception occurs.I don't know why internet
is getting disconnected suddenly. It works fine only if i re start the
emulator again. If any one knows and provides the solution, it will
be very much helpful for everyone.
See the below link:
http://hubpages.com/hub/Tips-to-solve-the-UnknownHostException-on-Android
Delete the old emulator and create a new one.
This will help

DDMS not able to send location to emulator

DDMS is not able to send location to the emulator. I have tried sending just the location from DDMS but still the emulator is not able to receive location. The application works properly in the device but its not able to capture location data in the emulator.
I am testing on Android 2.2 emulator. Can anyone let me know what can be the issue?
Make sure your AVD has GPS support hardware set to true
Create New AVD > Hardware > New > GPS support
Value should be "yes"
Also, ensure your app is requesting location updates in some way, otherwise the emulator will just ignore any incoming locations from DDMS or the console.
I just use the android console via telnet, it always works.
Just open a command line and:
telnet localhost 5554
5554 is the port number of your emulator, it is usually that but might change, it can be on the window fram of the emulator as PORT:AVD_NAME.
You should be greeted with an Android console message.
To send positions to your device just type.
geo fix []
Two valid statements would be
geo fix -77.036519 38.896143
geo fix -77.036519 38.896143 100
Hope this helps, its not DDMS, but it works always. You can also feed it nmea sentences but I dont think you need that.
I don't know what your setup looks like, but I've had problems sending locations via DDMS using Windows XP and regional settings set to Swedish. Changing the regional settings to English(USA) solves the problem for me. I guess it has something to do with how numbers are formatted. With swedish settings numbers are formatted as 123 456 789,00 and with English(USA) as 123,456,789.00. Hope it helps
I had this problem and I resolve it by disabling the firewall,
hope it works for you.

Categories

Resources