Geolocation Cordva ionic framework Timeout Expired Error

This post will help u come out of scenario where u get error code 3 or Timeout expired error message from

navigator.geolocation.getCurrentPosition(function(position){
    //success
    alert('Latitude: '          + position.coords.latitude          + '\n' +
      'Longitude: '         + position.coords.longitude         + '\n' +
      'Altitude: '          + position.coords.altitude          + '\n' +
      'Accuracy: '          + position.coords.accuracy          + '\n' +
      'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
      'Heading: '           + position.coords.heading           + '\n' +
      'Speed: '             + position.coords.speed             + '\n' +
      'Timestamp: '         + position.timestamp                + '\n');
  },
  function(error) {
    alert('code: '    + error.code    + '\n' +
      'message: ' + error.message + '\n');

  },  {maximumAge: 0, timeout: 50000, enableHighAccuracy: false });

Now there are following prerequisites to solve out this error.

 

First,

<!-- cordova script (this will be a 404 during development) -->
http://cordova.js
http://cordova_plugins.js

<!-- ionic/angularjs js -->
http://lib/ionic/js/ionic.bundle.js

http://lib/ngCordova/dist/ng-cordova.min.js

The order matters how to order your script files in index.html

 Secondly,

<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>

This is my project config.xml. Notice that whitelist plugin is well installed and is configured by me to allow-intent to geo:*

Third,

We should install device, geolocation, network-information and test out that other plugins are working properly or not. We should that we are focused on geolocation not working error.

The timeout for geolocation code should be increased upto 50000 to make it test well that our code is working or not.

Finally lets work on your device. It might happen to you that your geolocation might be working on one device and not on other. So this should too be confirmed. Because if your code running well on one android device. Then problem is already solved. It might only be network issue on second.

While adding android platform to your project make sure that you have used following command. Because it will provide you latest cordova-android version. Other commands will never do out this job for you. Geolocation plugin always asks for cordova version > 5.0  To achieve this kindly use following code to add android platform to your project.

cordova platform add https://github.com/apache/cordova-android

or

ionic platform add https://github.com/apache/cordova-android

 

Ref : https://cordova.apache.org/announcements/2014/08/04/android-351.html

Conclusion, if my post solved your problem. Kindly reply a comment. Or mail me if your need further help at greatwebist@outlook.com

Advertisements

Codova vs Phonegap

http://blog.devgeeks.org/post/73789983750/cordova-vs-phonegap-an-update

Cordova vs. PhoneGap: An update

I see a lot of confusion still about the difference and relationship between Cordova and PhoneGap.

TL;DR: If you don’t need to use the cloud build service at PhoneGap Build, just use the Cordova CLI tools, not the PhoneGap ones.

Lemme see if I can start with the penny tour.

In the beginning, there was PhoneGap. It was an amazing project by a little company called Nitobi in Canada. It was open source, and it was good.

Then the little company and the name PhoneGap was bought by Adobe. Adobe did notbuy the actual PhoneGap codebase, just the people that worked on it, and the name. The actual open source project was donated to the Apache Software Foundation.

So now the open source project needed a new name. After a couple of false starts, eventually they came up with “Cordova” – the name of the street the Nitobi offices had originally been on in Vancouver.

For a bit over a year, “PhoneGap” was just the Adobe binary distribution of the Apache open source project “Cordova” – you could think of PhoneGap as Safari to Cordova’s WebKit.

Now, all of this has been better documented in a couple of other posts by smarter people. The problem lies in what’s happened since then.

In version 3.x of Cordova – and therefore PhoneGap – a shift was made towards heavy use of a Node-based command line interface (CLI). It handles everything from creation of the project, installing plugins, and finally building and even running the app. It’s awesome, by the way, and if you haven’t made the switch away from the shackles of IDEs like Xcode and Eclipse, I heartily encourage you to give it a try.

Anyway… at the PhoneGap Day US conference, back in July of 2013 in Portland, we released the 3.0.0 version of Cordova. At the same conference, a variation of the Cordova CLI was launched called the PhoneGap CLI. The first split in actual functionality between the two had finally arrived.

The PhoneGap CLI is a similar-but-different variation on the Cordova CLI. It does much of the same things and even uses the Cordova CLI under the hood. The biggest difference lies in its connection to Adobe’s cloud build service called PhoneGap Build. The PhoneGap CLI allows you to – from the command line – create and build apps using that service. You don’t need the SDKs for the various platforms installed on your machine.

However, aside from some small syntax differences – and a couple missing features, if I am to be honest – the use of PhoneGap Build is the only difference at the time of this article. So as I said in the TL;DR above, my advice is that if you don’t need to use the cloud build service at PhoneGap Build, just use the Cordova CLI tools, not the PhoneGap ones.

More importantly, whatever you do, do not “mix and match” in a single project. This will only make a big mess.

I hope that clears it up a bit… if not, please feel free to send me an email, or come and hit me up me in the #phonegap channel on Freenode IRC.