Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use navigator.geolocation or $cordovaGeolocation in Ionic

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?

like image 614
Nikola Avatar asked Feb 09 '23 04:02

Nikola


1 Answers

$cordovaGeolocation is angular wrapper over plain javascript plugin, developed by ionic. 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.

So my conclusion is, you should go with $cordovaGeolocation.

like image 80
Mudasser Ajaz Avatar answered Feb 16 '23 12:02

Mudasser Ajaz