现在我正在构建一个离子应用程序来获取用户位置并启动 他们到一个特定的地方我们举办的活动 - 但首先,我保存了 用户纬度和经度到firebase然后用户点击 启动导航我们将启动的 launchNavigator()方法。 但问题是纬度和经度正在回归 未定义
这是我的代码:
app.controller('HomeCtrl', function($timeout, $scope, $state, $ionicPopup, $localStorage, $firebaseAuth, $firebaseArray, $firebaseObject, PresenceService,
$ionicLoading, HomeService, $cordovaGeolocation, $cordovaLaunchNavigator){
$scope.Data ={
lat : '',
long: ''
};
$scope.Get =HomeService;
$scope.hasMore = function(){
$scope.check =ListAllUserService.hasMore;
return $scope.check;
};
$scope.LoadAllUser =function(){
$ionicLoading.show({template:'Loading...'});
$scope.Get.load().then(function(data){
$scope.data =data;
console.log($scope.data);
$ionicLoading.hide();
var posOptions = {timeout: 40000, enableHighAccuracy: false};
$cordovaGeolocation.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
console.log(lat + ' ' + long);
$scope.Data.lat =lat;
$scope.Data.long =long;
var dataToDb = {latitude: lat, longitude: long, timestamp: new Date().getTime()};
var InsertChatRef = new Firebase('https://bigzill.firebaseio.com');
var insertObj =InsertChatRef.child('GeoLocation').child($scope.data.username);
insertObj.push(dataToDb);
}, function(err) {
console.log(err)
});
});
}
$scope.LoadAllUser();
$scope.launch = function(){
$ionicPopup.alert({
title : "GPS navigation"+ $localStorage.lat,
template: "Navigation Launch"+ $localStorage.long
});
}
$scope.launchNavigator = function() {
$ionicPopup.alert({
title : "GPS Just Launch"+ $scope.Data.lat,
template: "Navigation Launch"+ $scope.Data.long
});
var lat =$scope.Data.lat;
var long =$scope.Data.long;
console.log(lat + ' ' + long);
var destination = [lat, long];
var start = "Benin City, Oka Market";
$cordovaLaunchNavigator.navigate(destination, start).then(function() {
console.log("Navigator launched");
$ionicPopup.alert({
title : "GPS navigation",
template: "Navigation Launch"
});
}, function (err) {
console.error(err);
console.log(lat + ' ' + long);
$ionicPopup.alert({
title : "GPS fail "+ lat,
template: "Navigation Launch "+ long
});
});
};
});
这是我的Html
<ion-view view-title="Home Page">
<ion-content class="has-tabs" style="">
<div class="list card">
<div class="item item-avatar">
<img ng-src="{{data.image_name}}">
<h2>{{data.username}}</h2>
<p>November 05, 1955</p>
</div>
<div class="item item-body">
<img class="full-image" ng-src="{{data.image_name}}">
<p>
This is a "Facebook" styled Card. The header is created from a Thumbnail List item,
the content is from a card-body consisting of an image and paragraph text. The footer
consists of tabs, icons aligned left, within the card-footer.
</p>
<p>
<a href="#" class="subdued">1 Like</a>
<a href="#" class="subdued">5 Comments</a>
<a href="#" class="subdued" ng-model="Data.lat">{{Data.lat}} ' lat'</a>
<a href="#" class="subdued" ng-model="Data.long">{{Data.long}} ' long'</a>
<div ng-click="launchNavigator()">Launch Navigation</div>
</p>
</div>
</div>
</ion-content>
</ion-view>