当前位置和上一个位置之间的x米不同时,Android地图将位置更新到服务器 [英] Android map Update location to server when there is difference of x meters between current location and last location

查看:96
本文介绍了当前位置和上一个位置之间的x米不同时,Android地图将位置更新到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当当前位置和先前位置之间的x米不同时,我想用当前位置的latlong更新服务器.

我有一个想要跟踪车辆运动的应用程序,因此当驾驶室的当前位置与先前存储的位置之间存在x米的差异时,在车内使用该应用程序的驾驶员将自动更新其当前位置.这样其他用户将可以找到该驱动程序的确切位置.(因此,在这种情况下,我应该运行一个线程来自动请求更新当前位置或其他内容).

如何找出两个latlong点之间的距离,以便我可以找出当前位置和先前存储的位置之间的差是否为X米.

如果我使用requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)功能,我将能够以X米的形式提供minDistance,它可以完成工作,但不能为服务器提供准确的更新.

我在此处遇到了这个问题但由于我是初学者,所以没有明确的主意. 因此,如果有人帮助我实现这一目标,我将不胜感激.

解决方案

您可以使用此处阅读文档./p>

在创建 LocationRequest 您可以使用 setInterval setFastestInterval 或使用此答案.

I wanted to update the server with latlong of current location when there is difference of x meters between current location and previous location.

I have a app where i wanted to track vehicle movement so the driver who is using that app inside the vehicle will automatically update its current location when there is difference of x meters between current position of cab and previously stored location. So other users will be able to locate this driver where exactly is.(So in this case should i run a thread to automatically request for update of current location or something).

How to find out if the distance between two latlong points so that i can find out if the difference between current location and previously stored location is X meters.

If i use requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) function i will be able to provide minDistance as X meters and it would do the job but it is not giving accurate update to server.

I have gone through this question here but as i am a beginner did not have clear idea. So i would appreciate if somebody helps how i can achieve this.

解决方案

You can use the Google Play Services Location API. Read the documentation about how to recive location updates here.

When creating a LocationRequest you can specify how often you want to receive the updates using setInterval and setFastestInterval or the minimum distance between updates using setSmallestDisplayments.

When you receive an update you can store the latitude and longitude in shared preferences and use those values the next time you receive an update.

If you want to check if the distance between the two locations is greater than the minimum distance you specified you can do so using Location.distanceBetween.

For information on how to save the location data in shared preferences see this answer.

这篇关于当前位置和上一个位置之间的x米不同时,Android地图将位置更新到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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