Use navigator.geolocation or $cordovaGeolocation in Ionic
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts, I will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.
As you may know, I’m really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I’m in the top All time answerers list.
I actually asked this question myself:
Since I basically can get the same info with both approaches, I’m wondering which is the preferred one and what are the advantages using one over the other?
Answer, from user Mudasser Ajaz, was:
$cordovaGeolocation
is angular wrapper over plain javascript plugin, developed byionic
. Now question is why ngCordova was introduced,in simple words to deal it as plugin service as module and inject plugin wrapper as dependency to only particular controller or service.
On Pratical level, cordova developers were having issues with plugins on angular project. One simple issue was that$scope
does not get updated sometimes in simple plugins callback.
Quoting from ionic blog post :The services support promises to make it easier to deal with their asynchronous nature and ensure scope data is properly updated
https://twitter.com/HitmanHR/status/671057737669832705
Leave a Comment