距离的GPS应用 [英] Distance for GPS Application

查看:118
本文介绍了距离的GPS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  如何在Android上通过GPS跟踪距离?

我已经设计了一个GPS应用程序及其告诉我的位置很好。但现在我想包括更多的功能。我怎么会做出半径呢?有5或6公里,周边地区!我怎样才能提上该区域的地方,我的地方之间的距离?

I have designed a GPS application and its telling my location well. But Now I want to include more feature. How I will make a radius there? to have a surrounding area of 5 or 6 km! How I can mention the distance between a place on that area and my place?

推荐答案

我觉得这个问题开始变成一个很大的问题。我决定通过引导它朝着自己的问题的标题距离的GPS应用程序,以解决这个答案。

I feel like this question is starting to turn into a lot of questions. I decided to tackle this answer by directing it towards your question title "Distance for GPS Application".

在我的应用程序,而不是使用谷歌的API的请求从GPS的列表中的用户的距离通过执行以下坐标:

In my application, instead of using Google's API's I request the users distance from a list of GPS coordinates by doing the following:

在我的 JJMath 类:

获取距离(haversine公式,在英里):

/**
 * @param lat1
 * Latitude which was given by the device's internal GPS or Network location provider of the users location
 * @param lng1
 * Longitude which was given by the device's internal GPS or Network location provider of the users location 
 * @param lat2
 * Latitude of the object in which the user wants to know the distance they are from
 * @param lng2
 * Longitude of the object in which the user wants to know the distance they are from
 * @return
 * Distance from which the user is located from the specified target
*/
public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2-lat1);
    double dLng = Math.toRadians(lng2-lng1);
    double sindLat = Math.sin(dLat / 2);
    double sindLng = Math.sin(dLng / 2);
    double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    double dist = earthRadius * c;

    return dist;
}

然后我圆这个数字是:

/** This gives me numeric value to the tenth (i.e. 6.1) */
public static double round(double unrounded) {
    BigDecimal bd = new BigDecimal(unrounded);
    BigDecimal rounded = bd.setScale(1, BigDecimal.ROUND_CEILING);
    return rounded.doubleValue();
}

我不跟地图叠加的工作,但我相信有很多很好的教程或答案来。

I don't work with Map overlays, but I am sure there are great tutorials or answers to come.

这篇关于距离的GPS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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