从另一台设备实时定位安卓设备

Realtime locating of the android device from another device(从另一台设备实时定位安卓设备)
本文介绍了从另一台设备实时定位安卓设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个应用程序,我想在其中找到设备的确切位置.就像你坐出租车一样,我想找到出租车的确切位置.出租车司机将使用安卓设备.因此,我想通过该设备为其他想要查看出租车位置的用户定位出租车位置.

I have an app where i wanted to locate the exact location of the device. Like if you take taxi, i wanted to locate where exactly the taxi. Taxi driver will be using android device. So from that device i wanted to locate the cab location for other users who wants to see where the cab is.

我尝试使用 requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) 将出租车司机的当前位置上传到服务器,因为出租车移动了几米,我已经完成了这个更新位置当驾驶室按下某个启动按钮或其他东西时,驾驶室的驾驶室会不断发送设备的当前位置 X 米.

I have tried uploading current location of cab driver to server as cab moves for few meters by using requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) and I have done this updating location of cab when the cab press some start button or something it keeps sending the current location of the device for X meters.

其他用户将从该更新位置调用服务并找到出租车的当前位置.

From that updated location other users will call the service and find the current location of cab.

在用户端会有一张地图,他可以在其中看到出租车的当前位置.用户调用该服务以查看更新的位置.我通过在该活动上设置 TIMER 来调用服务,因此它会一次又一次地刷新并调用服务器.(设置定时器是最好的方法或任何其他方法).

At user side there will be a map where he can see the current location of cab. User calls the service to see updated location. I am calling the service by setting the TIMER on that activity so it refreshes and calls the server again and again.(Setting a timer is it best approach or any other ways of doing it).

但这种方法需要大量数据和电池,甚至不是实时的.有没有最好的方法来定位 android 设备,使它看起来至少是实时的.

But this approach takes lot of data and battery and it is not even realtime. Is there any best approach to locate the android device so that it seems to be realtime atleast.

推荐答案

Is there any best approach to locate the android device

您可以使用GCM 服务.

how it will help you?

它可以在驾驶室移动时发送带有当前latlng(每次位置更新)的推送消息.

It can send push messages with current latlng (for each location update) when the cab moves.

前:

@Override
public void onLocationChanged(Location location) {
    String latitude = String.valueOf(location.getLatitude());
    String longitude= String.valueOf(location.getLongitude());
    //Send push messages with current location
    // sendpushMessage(from_Number, to_Number/s, "Location "+ latitude +" "+ longitude;
}

您可以重复启动 IntentService,然后是 AlarmManager,并在每 5/10 秒内发送消息(位置),并在您喜欢时停止(例如,当 cab 在用户位置范围内时或类似情况时).

You can start repetitively an IntentService followed by AlarmManager and send messages(location) in each 5/10 seconds and stop whenever you like (e.g when cab is in range of user's location or something like this).

在用户的设备中,您可以收到有关出租车司机更改位置的消息.只需将这些更新的位置放在地图中并显示给用户.所以用户可以完美地看到正在运行的驾驶室.

In user's device you can get messages with cab driver's changing location. Just put these updated locations in map and show to the user. So the user can see the running cab perfectly.

在用户的设备中.. EX:

In User's Device.. EX:

GCMIntentService 的 onMessage() 方法中获取所有消息,例如:

 @Override
protected void onMessage(Context context, Intent intent) {
   String message = intent.getExtras().getString("message");
   //tokenize the string and get driver's location(latitude, longitude)
   //then update each latlng and show cab marker in user's map with a static method
}

注意:我们总是从这里开始通知(onMessage()).所以请确保您没有使用任何通知,否则它会通过带有新位置消息的多个通知来干扰用户.

这种方法对电池很有帮助.此外,您不必每次都检查服务器以继续更新.它会在您需要时自动将消息推送到用户的设备,并且接收者可以完美地接收每条消息.

This approach is very helpful for battery. Also you don;t have to check the server each time for continue update. it will automatically push messages to user's device whenever you want and the receiver can able to receive each message perfectly.

这篇关于从另一台设备实时定位安卓设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Change the style of AlertDialog(更改 AlertDialog 的样式)
Pop up dialog in Android home screen(在 Android 主屏幕中弹出对话框)
How to display an existing ListFragment in a DialogFragment(如何在 DialogFragment 中显示现有的 ListFragment)
When to use Android PopupWindow vs Dialog(何时使用 Android PopupWindow vs Dialog)
Android: Close dialog window on touch(Android:触摸时关闭对话框窗口)
Android - Executing a custom listview in a custom dialog properly(Android - 在自定义对话框中正确执行自定义列表视图)