ionic-team / ionic-starter-maps

An Ionic starter project using Google Maps and a side menu
144 stars 58 forks source link

map not created or on-create not called #14

Open yailPeralta opened 8 years ago

yailPeralta commented 8 years ago

I have this error: angular.js:13424 TypeError: Cannot read property 'setCenter' of undefined at $cordovaGeolocation.getCurrentPosition.then.Dialogs.alert.title (create-spot.controller.js:33) at processQueue (angular.js:15757) at angular.js:15773 at Scope.$eval (angular.js:17025) at Scope.$digest (angular.js:16841) at angular.js:17064 at completeOutstandingRequest (angular.js:5824) at angular.js:6100(anonymous function) @ angular.js:13424(anonymous function) @ angular.js:10137processQueue @ angular.js:15765(anonymous function) @ angular.js:15773$eval @ angular.js:17025$digest @ angular.js:16841(anonymous function) @ angular.js:17064completeOutstandingRequest @ angular.js:5824(anonymous function) @ angular.js:6100

And here is the code that i'm using:

`function CreateSpotController($scope, $cordovaGeolocation, Dialogs, $ionicPlatform) { $scope.showMap = false;

$scope.getCurrentPosition = function (options) {

  $scope.mapCreated = function (map) {
    $scope.map = map;
  };

  options = options || {
    timeout: 10000,
    enableHighAccuracy: false
    //maximumAge: 5000
  };

  $ionicPlatform.ready(function () {

    $cordovaGeolocation
      .getCurrentPosition(options)
      .then(function (position) {
        //show map
        $scope.showMap = true;

        $scope.latitude = position.coords.latitude;
        $scope.longitud = position.coords.longitude;

        $scope.map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));

      }, function(error) {
        // error
        Dialogs.alert({
          title: 'Error',
          message: error,
          buttonName: 'Aceptar'
        });
      });

  });

}; // end getCurrentPosition

} // end CreateSpotController`

can you help me please?