【问题标题】:Track an user with location based App使用基于位置的应用程序跟踪用户
【发布时间】:2015-03-22 13:00:48
【问题描述】:

我正在开发基于位置的应用程序。在这里,我的要求是我想从我的设备(如 uber 或 Ly ft App)跟踪用户位置。 示例:如果一个披萨人(用户 B)想给我(用户 A)送披萨,那么他可以分享他的用户 ID,因此使用该 ID,我可以输入我的设备并查看他的确切位置。但我想跟踪他,直到我需要如何在代码中实现这一点。如果您遇到这种情况,请帮助我了解架构。

我也可以实现上述场景,但我的疑问是我如何在地图中显示而不刷新每次用户移动时例如两分钟,一旦我想检查纬度和经度并在我的地图中更新它同一个用户

【问题讨论】:

    标签: android google-cloud-messaging android-maps-v2 android-maps-utils


    【解决方案1】:

    创建一个线程,要求 Handler 多次获取位置。您需要使用 Handler,因为 getMyLocation 方法只能从 GUI Thread 调用:

    private class MyLocationThread extends Thread{
        @Override
        public void run() {
            int loops = 0;
            // we give the location search a minute 
            while(loops < 60){
                // we have to try it over a handler, because getMyLocation() has to be called from GUI Thread -_-
                _getMyLocationHandler.sendEmptyMessage(0);
                if(isInterrupted()){
                    return;
                }
                // take a short nap before next try
                try {Thread.sleep(1000);} catch(Exception e){}
                loops++;
            }
    
        }
    }
    

    这是处理程序的作用:

    private Handler _getMyLocationHandler = new Handler(){
        public void handleMessage(android.os.Message msg) {
            if(getMap().isMyLocationEnabled() && getMap().getMyLocation() != null){
                _locationWatcher.interrupt();
                drawCurrentImagePositions();
            }
        }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多