Open kunalnagar opened 9 years ago
I have the same Issue with Android 4.4.4 API 19
I am the same problems with Nexus 5 android 5.0.0 API 21. I have test also with my galaxy note 8 and it still giving the same message even I have 1 minutes for timeout.
I spent hours today struggling with this issue. Geolocation kept timing out on android 5.0 and 5.1. Installing version 1.0 of the cordova geolocation plugin (I had version 0.3.x before) did it for me.
According to [https://issues.apache.org/jira/browse/CB-5977](this link), this version only adds the required location permissions to the AndroidManifest.xml file, and leaves the rest of the work to the Web geolocation API instead of the device's native one.
So,
cordova plugin rm org.apache.cordova.geolocation
cordova plugin add cordova-plugin-geolocation
Then just use the Web API :
navigator.geolocation.getCurrentPosition(
successCallback,
errorCallback,
options
);
Hope this helps
same issue here, I am not getting working. I am using cordova-plugin-geolocation
. I tested in kikat and lollipop.
I manually modified the /plugins/android.json file, the plugin didn't add itself to this file. I added the "xml:" and "count" lines.
The config.xml and AndroidManifest.xml are overwritten by this JSON
plugin v0.3.12 Android 4.4.4 API 19
{
"prepare_queue": {
"installed": [],
"uninstalled": []
},
"config_munge": {
"files": {
"res/xml/config.xml": {
"parents": {
"/*": [
{
"xml": "<feature name=\"Geolocation\"><param name=\"android-package\" value=\"org.apache.cordova.geolocation.GeoBroker\" /></feature>",
"count": 1
}
]
}
},
"AndroidManifest.xml": {
"parents": {
"/*": [
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />",
"count": 1
},
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />",
"count": 1
},
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_LOCATION_EXTRA_COMMANDS\" />",
"count": 1
}
]
}
}
}
},
"installed_plugins": {
"org.apache.cordova.geolocation": {
"PACKAGE_NAME": "com.example.hello"
}
},
"dependent_plugins": {}
}
Adding on as another case where the geolocation is failing. Running Android 5.1 with Location turned on (I can see the app as a requestor when looking at my Locations permissions).
Using the web API does not solve the issue, either.
Did anybody got the solution for this problem. I'm also facing the same problem.
I had this problem, you need to add the whitelist plugin to the project and this to your main html file <meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
Hi digitalbath, I addded your meta tag in my html file.. Eventhough it is showing timeout error... If the internet connection is on with gps , the location is shown..But without internet it is not fetching the location.
if anyone is facing same issue and using ionic then just remove and install the plugin using ionic not cordova , why?... not sure! but i think it only works if added to package.json and it wont be added unless we run ionic not cordova , not sure but anyway it works for me!
so do this,
first check if it exists
ionic plugin list
if yes then remove it using ionic
sudo ionic plugin rm org.apache.cordova.geolocation
then install it again
sudo ionic plugin add org.apache.cordova.geolocation
hope this help! :)
Tried every recommendation above including those mention on stack overflow. nothing works. I am using API 23
@zmijevik Can you include a codepen that reproduces the issue? Or link to a minimal github repo that reproduces the issue?
@gortok It turns out that geolocation only works when high_accuracy is enabled. I had it disabled all this time because I thought it was contributing to the error:
var posOptions = {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
};
Also the same problem here using Ionic and the cordova-plugin-geolocation. Here is a bit more detailed error output from Google Chrome Inspect Devices on my Android Nexus 7 Tablet.
PositionError {
code: 3,
message: "Timeout Expired",
__proto__: {
...
message: [Exception: TypeError: Illegal invocation at PositionError.remoteFunction (<anonymous>:3:14) at Object.InjectedScript.callFunctionOn (<anonymous>:721:66)]
...
}
}
Basic outline of code I'm using: (Note: I'm using a custom api for the google map) This code works fine in-browser no matter if HighAccuracy is enabled or not.
var posOptions = {
enableHighAccuracy: false,
timeout: 20000,
maximumAge: 0
};
$cordovaGeolocation.getCurrentPosition(posOptions).then(
function (position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var myLatlng = new google.maps.LatLng(lat, lng);
var cityInfo = {};
$http
.get('https://maps.googleapis.com/maps/api/geocode/json?latlng='+myLatlng.G+', '+myLatlng.K+'&key='+myApiKey)
.then(
function successCallback(response) {
// console.log(response.data);
if(response.data.status == 'OK') {
cityInfo.cityLat = response.data.results[0].geometry.location.lat;
cityInfo.cityLong = response.data.results[0].geometry.location.lng;
if (response.data.results[0]) {
// console.log(response.data.results[0]);
for(var i=0; i<response.data.results[0].address_components.length; i++) {
if(response.data.results[0].address_components[i].types[0] == 'postal_code') {
var postal_code = response.data.results[0].address_components[i].short_name;
$scope.postal_code = postal_code;
}
}
}
getMap(cityInfo);
}
},
function errorCallback(response) {
alert('Failed: '+response);
}
);
function getMap(cityInfo, polygons) {
uiGmapGoogleMapApi.then(function(maps) {
$scope.map = {
center: { latitude: cityInfo.cityLat, longitude: cityInfo.cityLong },
zoom: 11
};
$scope.options = {
disableDefaultUI: true,
disableDoubleClickZoom: true,
draggable: false
};
// $scope.polygons = polygons;
});
$ionicLoading.hide();
}
}, function(err) { // Geolocation Fails
$ionicLoading.hide();
console.log(err); // This is where it outputs PositionError
}
);
Can somebody simply confirm that it's not possible ? I can't find a way to make it works.
Any solution yet ? Its been so many days i am struggling with this issue ! any possible alternatives?
UP
17 Developers between 2 different company headquarters AND NONE of us can get this plugin to work. Followed every "mod" and "tweak" out there. Giving up + creating a custom java plugin instead. What a waste of time and money
I had a similar problem for the last couple of days. Using Ionic and ngCordova, $cordovaGeolocation getCurrentPosition method timed out when testing it on a Nexus 4 device. It did, however, work flawlessly on iPhone. As it turns out, the reason was that the device was without a Sim Card. The GPS chip won't work without a Sim Card. After testing it on another Android Device (with a working Sim Card) it worked fine.
Hope this helps someone.
@AlexMilmanGitHub That could totally be it. I'm going to have to try this now. Will update if I can confirm.
Has anybody solved this problem? On Android 4.x.x and 6 this plugin works fine. But on Android Lollilop always get timeout error Faced this problem after updating to cordova android@5.1.1 and API 23. Tried everything described here but nothing works.
@AlexMilmanGitHub i always have sim card in phone and internet connection i use is from wifi. Plugin works every time i test it on 4.4 device but fails on 4.2 device.
Has anybody solved this problem? i test in android 4.x work fine, but ini lollipop not work.....
Seems @AlexMilmanGitHub is right. I tried to run the test on a Nexus 7 tablet and I had the same Timeout Error. However, I tried on an Infinix Hot 3(Lollipop) and a Samsung S7 edge(Marshmallow), both with SIMs and it worked fine without issues.
SIM card did it for me. Couldn't get it to work otherwise.
I found this issue affecting specific manufacturers, like xiaomi and gionee. For the rest it is working fine. I am using Cordova v6.3, some one please help
I'm facing the same problems :-( I have a Android Tablet with 5.1 running, and no SIM, but the Google Map app shows the right location! With ionic2 native cordova plugin I still getting timeouts, even with 30000ms timeout setting.
br Meex
I also encountered this on a Nexus device. It means that we have had to scrap developing the app in the Ionic / Cordova environment. It is not fit for purpose when certain phones are unable to use such a core function as GPS.
:-/ but what is so hard on this, other android seem to support native GPS without any network connection? Maybe there is another cordova/phonegap plugin which supports this?
@tommydudehead have you tried this https://www.npmjs.com/package/cordova-plugin-advanced-geolocation?
@tommydudehead it worked :-) https://github.com/Esri/cordova-plugin-advanced-geolocation/issues/43#issuecomment-265849104
Tests on my Nexus7 (2013 - android 6.0.1) show that "high accuracy mode" must be selected in android location settings, (device only - gps) will not work.
The problem, as I understand is that ngcordova uses geolocation feature of webview, which is only available in 'high accuracy mode'.
I've tried cordova-plugin-geolocation with ngCordova but it always returned me Timeout error, meaning it can't get device's position in my even 5 minutes set timeout, so the final solution for Android 5.1 at least:
i've added permissions to AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NETWORK_ACCESS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
it wasn't working without ACCESS_WIFI_STATE
permission. Now it works even without a sim card, with wifi connected and location enabled.
In case someone will find it helpfull.
Hey @MikhailRoot Thanks man adding permissions in AndroidManifest.xml worked for me...
any one have a working example please ?
I added the permissions in AndroidManifest.xml I'm using a andoid 6, tried to install cordova-plugin-advanced-geolocation but don't know how to make it work. cordova-plugin-advanced-geolocation is for android only so what happen if it's run on iphone or older android ?
I'm having the same issue with a moto g4 plus with android 7 (nougat), always with a sim card, high precision GPS, high accuracy, I've tried practically everything you guys said but always get a timeout...
Geolocation works fine on other devices with lollipop and used to work fine on marshmallow on the same device (moto g4 was recently updated from marshmallow to nougat). Also working fine on iOS.
There are no warnings and no traces, only the timeout error.
in my case it work now, my GPS phone bug ( on all gps application, jumping from place to place after a recent falldown). i restart my device and it work
@alainib Thanks man, I restarted the device and everything works again!
@alainib thanks Man, I restarted my mobile and It is working very fine with enableHighAccuracy: false/true
i want to share my experience with u , after android M.M android set many restrictions , like restrict in fetching mac id only (000000000000) is hard-coded and locations etc., i was using same geo location fetching phonegap plugin , and was getting timeout again and again, than i found one solution. just go on google maps app and location sharing option from side navigation and allow your location to share. than again open your app again and you will find exact lat long of your device. could be i am wrong but just sharing my R&D with u . thanks
Anybody fix timeout error PositionError {code: 3, message: "Timeout expired"} in the console.it occur only if GPS off then ON the GPS its working in such case?
I'm testing the ngCordova Geolocation service on a Nexus 5 and it is timing out every time.
Phone: Nexus 5 with Android Lollipop 5.1 ngCordova Version: v0.1.12-alpha Location Services: Turned on with Battery Saving Mode Run Environment: ionic run android -l (using LiveReload)
Here is the error:
and here is my code (nothing special):
Anyone know why this is happening? Same code is working on One Plus One and Samsung devices though.