2017-03-09 23 views
-1

我在離子2個新的,我面對..我都遵循一個教程here其中一些ocation來自我mysqldatabase一個問題...我想列出的離我最近的我CURENT位置放置...離子2適用haversine公式我CURENT位置應用

我不能在平臺上準備好用戶的位置,然後將GPS位置,我需要提前申請的排序算法..請別人幫助會感激..謝謝...

回答

0

import {Geolocation} from 'ionic-native'; 
 

 
Geolocation.getCurrentPosition().then(pos => { 
 
    console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude); 
 
}); 
 

 
let watch = Geolocation.watchPosition().subscribe(pos => { 
 
    console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude); 
 
});

等待ondeviceready或使用platform.ready()如果你使用離子框架2個

this.platform().then(() => { 
Geolocation.getCurrentPosition().then(pos => { 
    console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude); 
}); 
); 
}); 
+0

感謝我解決問題 –