使用基于位置的应用程序跟踪用户
Track an user with location based App
我正在开发基于位置的应用程序。我的要求是我想从我的设备(如 uber 或 Ly ft App)跟踪用户位置。
示例:如果披萨店员(用户 B)想给我(用户 A)送披萨,那么他可以分享他的用户 ID,因此使用该 ID,我可以进入我的设备并查看他的确切位置。但我想跟踪他,直到我需要如何在代码中实现这一点。有遇到这种情况的可以帮我架构一下。
我也可以实现上述场景,但我的疑问是,当用户移动时,我如何在不刷新的情况下显示在地图中,例如,一旦我想检查纬度和经度并在我的中更新它,例如两分钟同一用户的映射
创建一个线程,要求处理程序多次获取位置。您需要使用 Handler,因为 getMyLocation 方法只能从 GUI 线程调用:
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();
}
}
};
我正在开发基于位置的应用程序。我的要求是我想从我的设备(如 uber 或 Ly ft App)跟踪用户位置。 示例:如果披萨店员(用户 B)想给我(用户 A)送披萨,那么他可以分享他的用户 ID,因此使用该 ID,我可以进入我的设备并查看他的确切位置。但我想跟踪他,直到我需要如何在代码中实现这一点。有遇到这种情况的可以帮我架构一下。
我也可以实现上述场景,但我的疑问是,当用户移动时,我如何在不刷新的情况下显示在地图中,例如,一旦我想检查纬度和经度并在我的中更新它,例如两分钟同一用户的映射
创建一个线程,要求处理程序多次获取位置。您需要使用 Handler,因为 getMyLocation 方法只能从 GUI 线程调用:
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();
}
}
};