从其他设备实时定位android设备 [英] Realtime locating of the android device from another device

查看:125
本文介绍了从其他设备实时定位android设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想找到设备的确切位置。就像如果你乘坐出租车,我想找出出租车的位置。出租车司机将使用Android设备。因此,从该设备中,我想找到其他用户想要查看驾驶室位置的驾驶室位置。



我尝试将当前出租车司机的位置上传到服务器驾驶室通过使用 requestLocationUpdates(String provider,long minTime,float minDistance,LocationListener listener)移动几米,当驾驶室按下某个开始按钮时,我已经完成了驾驶室的更新位置或者它一直发送X米的设备的当前位置。



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



在用户那边会有一张地图,他可以看到驾驶室的当前位置。用户调用服务以查看更新的位置。我通过在该活动上设置TIMER来调用该服务,以便刷新并一次又一次地调用服务器(设置计时器是最佳方法或其他方式)。

但是这种方法需要大量的数据和电池,甚至不是实时的。有没有什么最好的方法来找到Android设备,以便它似乎是实时的。

解决方案

 是否有任何找到Android设备

您可以使用 GCM服务

 它将如何帮助你? 

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



EX:

  @Override 
public void onLocationChanged位置){
String latitude = String.valueOf(location.getLatitude());
String longitude = String.valueOf(location.getLongitude());
//发送带有当前位置的推送消息
// sendpushMessage(from_Number,to_Number / s,Location+ latitude ++ longitude;
}



您可以重复启动一个IntentService,接着是AlarmManager并发送消息(地点),每5/10秒钟停一次,并随时停止(例如,当驾驶室在用户位置范围或类似的地方)。



在用户设备中,您可以获得信息与出租车司机的位置变化,只需将这些更新的位置放置在地图中并显示给用户即可,因此用户可以完美地看到驾驶室。



在用户设备中。 EX:



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

  @Override 
protected void onMessage(Context context,Intent intent){
String message = intent.getExtras()。getString(message );
//标记字符串并获取驱动程序的位置ion(纬度,经度)
//然后用静态方法更新每个latlng并在用户映射中显示出租车标记
}

注意:我们总是从这里开始通知(onMessage())。因此,请确保您没有使用任何通知,否则会通过多个通知发送新的位置信息来干扰用户。

这种方法对电池非常有用。此外,您不必每次都检查服务器以便继续更新。它会自动将消息推送到用户的设备,并且接收者能够完美地接收每条消息。

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.

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.

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).

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

You can use GCM service.

how it will help you?

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

EX:

@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;
}

OR

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.

In User's Device.. EX:

Get all messages in your GCMIntentService's onMessage() method like:

 @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
}

NOTE: we always start notification from here(onMessage()). So make sure you have not use any notifications , otherwise it disturbs the user through multiple notifications with new location message.

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.

这篇关于从其他设备实时定位android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆