Android OLA和UBER如何计算计费距离
我想开发一个小应用程序,计算旅行时的距离。 我尝试了以下基于Android GPS的解决方案,但结果是错误的 请帮我做这个 我的代码:Android OLA和UBER如何计算计费距离,android,location,Android,Location,我想开发一个小应用程序,计算旅行时的距离。 我尝试了以下基于Android GPS的解决方案,但结果是错误的 请帮我做这个 我的代码: locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 10, this);
locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 10, this);
public void onLocationChanged(Location location) {
if ((location != null)) {
if (location.getAccuracy()<50 && location.getSpeed()>0) {
onlocationChangeMethod(location);
lastlatitude = location.getLatitude();
lastlongitude = location.getLongitude();
}
}
}
public void onlocationChangeMethod(Location location){
if (lastlatitude > 0 ) {
float[] results = new float[5];
location.distanceBetween(location.getLatitude(), location.getLongitude(),
lastlatitude, lastlongitude, results);
}
}
locationManager=(locationManager)getActivity().getSystemService(Context.LOCATION\u服务);
locationManager.RequestLocationUpdate(locationManager.GPS_提供程序,0,10,此);
已更改位置上的公共无效(位置){
如果((位置!=null)){
if(location.getAccurance()0){
onlocationChangeMethod(位置);
lastlatitude=location.getLatitude();
lastlongitude=location.getLongitude();
}
}
}
public void onlocationChangeMethod(位置){
如果(lastlatitude>0){
浮动[]结果=新浮动[5];
location.distanceBetween(location.getLatitude(),location.getLatitude(),
最后纬度、最后经度、结果);
}
}
只有在非常频繁地获取gps位置时,距离才能精确。因此,一种方法是根据gps坐标偏移计算距离。这不可能100%准确
还听说Ola/Uber汽车仪表板内安装了内部跟踪设备,可以准确跟踪车队并与其服务器进行通信(跟踪设备随sim卡提供,以便它们可以与安装了网关的服务器进行通信)。这意味着,如果Ola和Uber的距离如此精确,他们可能依赖安装在汽车仪表板内的跟踪设备,并通过服务器获取信息。GPS:
把A作为起点。
每X秒(比如10秒)增加2个点(A和当前位置)之间的GPS距离。检查Android位置。distanceTo
或distanceBetween
<代码>检查我的曲目应用程序,它是开源的。GPS在室内不可用,如果用户频繁改变方向(每1-2秒读取一次),则会出现错误
要获得准确的距离,请使用您的位置纬度和经度致电Google WebService,它将返回非常接近准确的距离
private String getDistanceOnRoad(double latitude, double longitude,
double prelatitute, double prelongitude) {
String result_in_kms = "";
String url = "http://maps.google.com/maps/api/directions/xml?origin="
+ latitude + "," + longitude + "&destination=" + prelatitute
+ "," + prelongitude + "&sensor=false&units=metric";
String tag[] = { "text" };
HttpResponse response = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
response = httpClient.execute(httpPost, localContext);
InputStream is = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(is);
if (doc != null) {
NodeList nl;
ArrayList args = new ArrayList();
for (String s : tag) {
nl = doc.getElementsByTagName(s);
if (nl.getLength() > 0) {
Node node = nl.item(nl.getLength() - 1);
args.add(node.getTextContent());
} else {
args.add(" - ");
}
}
result_in_kms = String.format("%s", args.get(0));
}
} catch (Exception e) {
e.printStackTrace();
}
return result_in_kms;
}
参考:你是如何计算距离的?你能给我们看一下代码吗?谢谢你的回复。我已经添加了我的代码。我想
distanceBetween
方法给出了直线距离。是吗?是的,它会给出直线距离。所以,你计算的是“空中线距离”,而不是实际的跟随路径(总是更大)。谢谢你的信息。但GPS有时无法连接,每次都会给出错误的距离。例如,如果我行驶2公里,则会出现400米的差异。请检查我的编辑。他们也使用内部车队追踪设备。谢谢阿姨。这很有帮助。谢谢你提供的信息。我正在使用相同的方法,但错误的距离正在到来。我要求每10米更新一次位置,我正在添加该距离。但是这个距离不对,谢谢。我需要的应用程序工作没有互联网也。有时GPS坐标会离我现在的位置很远。在这种情况下,距离是wrong@MallikarjunP你的出租车应用程序运行正常吗?现在?我从来没有为出租车应用程序编写过代码,但知道它的工作原理。试试看