【问题标题】:Fire location event for test purpose用于测试目的的火灾定位事件
【发布时间】:2017-05-10 11:23:26
【问题描述】:

我正在测试 Android 的地理定位功能。

我需要离开几米才能触发这个事件。

(另一方面,在 iOS 上,当我启动应用程序时会触发此功能, 我的 iphone 是 4G ,但 android 使用 Wifi,这可能是原因。)

有没有什么好的方法可以触发这个函数来进行测试??

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

【问题讨论】:

    标签: android geolocation titanium


    【解决方案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 事件侦听器。

    【讨论】:

      【解决方案2】:

      在 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
          }));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        • 2013-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多