Controller page
.controller('SomeController', function (SomeDataFactory,$scope,$state) {
var _this = this;
var latitude;
var longitude;
var radious;
$scope.data = {};
$scope.address = function ($scope) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
radious = 10;
});
console.log(latitude);
console.log(longitude);
console.log(radious);
}
}
SomeDataFactory.getSomeData(latitude, longitude, radious).then(function (response) {
alert(response);
//do something with response
_this.data = response.data;
}).catch(function (response) {
//handle the error
});
});
Service.js page
.factory('SomeDataFactory', function ($http) {
var url = 'http://192.168.1.100:2016/Ionic_AppServices.svc/?Addresss';
return {
getSomeData: function () {
return $http.jsonp(url);
}
}
});
我正在尝试使用AngularJS和Geolocation获取我的位置的纬度和经度。这是控制器中的功能,我在其中分配纬度和经度的值并将它们打印到浏览器控制台。调用address()函数,