Plugin sayfası: http://ngcordova.com/docs/plugins/geolocation/
proje dizinimize gelip terminalden plugini ekleyelim:
$ cordova plugin add cordova-plugin-geolocation
Sayfa bağlantısını yapalım:
www/templates/location.html
<ion-view view-title="Location">
<ion-content>
<br/>
<h3>koordinat Uygulaması</h3>
<br/>
<button class="button button-balanced button-block" ng-click="getlocation()">kordinat getir</button>
<div class="item item-text-wrap">
x: {{lat}}
<br>
y: {{lon}}
</div>
<br/>
</ion-content>
</ion-view>
www/templates/menu.html
<ion-list>
*
*
<ion-item menu-close ui-sref="app.locatiom">
Location
</ion-item>
*
*
</ion-list>
www/js/app.js içerisine aşağıdaki kodları yazalım
.state('app.location',{
url:'/location',
views: {
'menuContent': {
templateUrl: 'templates/location.html',
controller:'LocationCtrl'
}
}
})
www/js/controller.js içerisine:
.controller('LocationCtrl',function($scope, $cordovaGeolocation){
$scope.getlocation=function(){
var posOptions = {timeout: 10000, enableHighAccuracy: true,maximumAge: 0};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
$scope.lat = position.coords.latitude;
$scope.lon = position.coords.longitude;
}, function(err) {
alert(err);
})
}
})
çalıştırmadan önce gps i açmayı unutmayalım:
Hiç yorum yok:
Yorum Gönder