2017-05-10 36 views
0

我測試了Android的地理定位功能。用於測試目的的消防位置事件

我需要離開幾米才能開火這個事件。

(在另一方面,在iOS這個功能被觸發,當我啓動應用程序, 我的iPhone是4G,但Android使用無線網絡,它可能是這個原因。)

有火有什麼好的方法這個功能用於測試目的?

Ti.Geolocation.addEventListener('location', function(e) { 
    if (e.error) {  
     } else { 
      Ti.API.info(e.coords); 
    } 
}); 

回答

1

在你,我會做這樣的事情:

var locationListener = function(e) { 
    if (e.error) {  
     } else { 
      Ti.API.info(e.coords); 
    } 
}; 
Ti.Geolocation.addEventListener('location', locationListener); 
Ti.App.addEventListener('testLocation', locationListener); 

而且我會火testLocation當它爲您提供更好的:

Ti.App.fireEvent('testLocation', {success: true, coords: {latitude: 0, longitude: 0}}); 

顯然設置的參數與所有的您需要的屬性(http://docs.appcelerator.com/platform/latest/#!/api/LocationCoordinates),並且不要忘記從Ti.App中移除testLocation事件偵聽器。

0

的addEventListener安裝前Ti.geolocation.Android

Ti.Geolocation.Android.manualMode = true; 
    Ti.Geolocation.Android.addLocationProvider(Ti.Geolocation.Android.createLocationProvider({ 
     name : Ti.Geolocation.PROVIDER_GPS, 
     minUpdateDistance : 1, // 1 metre 
     minUpdateTime: 1 // one per second 
    })); 
    Ti.Geolocation.Android.addLocationRule(Ti.Geolocation.Android.createLocationRule({ 
     provider : Ti.Geolocation.PROVIDER_GPS, 
     accuracy : 50, // Updates should be accurate to 50m 
     maxAge: 1000, // Updates should be no older than 1 seconde 
     minAge: 200, // But no more frequent than 5 per seconds 
    }));