Alternative to Cordova Geolocation Plugin for getting current position

Hi Everyone,

I’m new to Ionic and developing an app integrating with Google Map API. My code is working well on browser but I need to install cordova geolocation to make the function navigator.geolocation.getCurrentPosition works on Android Device (Nexus 5) (cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git).

Do you have any suggestion to improve this? Since I dont really understand how cordova geolocation plugin works and why I need it for my app :smile:

This is my codes:

/* ========== Transaction Page ========== */
<ion-view view-title="Transaction History" ng-controller="TransactionController">
  <div class="bar bar-header map-div">
    <div id="map"></div>
  </div>
  <ion-content scroll="true" class="transaction">
    {{accountNumber}}
  </ion-content>
</ion-view>

/* ========== Transaction Page Controller ========== */
.controller('TransactionController', function($scope, $state, $ionicLoading, $stateParams) {
  $scope.accountNumber = $stateParams.accountNumber;
  $scope.productName = $stateParams.productName;

  $scope.drawMap = function() {
    var myLatlng = new google.maps.LatLng(144.94623769999998, -37.8216962);

    var mapOptions = {
      center: myLatlng,
      zoom: 13
    };

    $scope.map = new google.maps.Map(document.getElementById("map"),
      mapOptions);

    // Try HTML5 geolocation
    if (navigator.geolocation) {
      console.log("Device supports Geolocation");
      navigator.geolocation.getCurrentPosition(function(position) {
        console.log("Enter getCurrentPosition");
        var pos = new google.maps.LatLng(position.coords.latitude,
          position.coords.longitude);
        console.log(pos);
        $scope.map.setCenter(pos);

        var myLocation = new google.maps.Marker({
          position: pos,
          map: $scope.map,
          content: 'Your location'
        });
      });
    } else {
      // Browser doesn't support Geolocation
      console.log("Device doesn't support Geolocation");
    }
  };

  $scope.drawMap();
});