0
我试图用科尔多瓦地理位置插件让我的位置更新和我的控制器的样子:离子范围将不会内部功能
.controller('HomeCtrl', function($scope,$cordovaGeolocation,$ionicLoading) {
$scope.location="location";
$ionicLoading.show({
template: '<ion-spinner icon="bubbles"></ion-spinner><br/>Acquiring location!'
});
var posOptions = {
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 0
};
$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
var request = {
latLng: latlng
};
geocoder.geocode(request, function(data, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (data[3] != null) {
$scope.location=data[3].formatted_address;
console.log($scope.location);
} else {
console.log("No address available");
}
}
})
$ionicLoading.hide();
}, function(err) {
$ionicLoading.hide();
console.log(err);
});
})
在视图中的$scope.location
值仍然是“位置”,虽然它已经更新了地理编码器功能。但是当我在控制台日志中显示它时,它会显示我目前的城市。谁能帮我?
这里是我的HTML
<ion-content scroll="true" ng-controller="HomeCtrl">
<h3>{{location}}</h3>
</ion-content>
谢谢,它的工作 –
标记答案是正确的,如果它帮助你。 – Iansen