android-查找最近的位置,以我现在的位置 [英] android- Find nearest location to my current place

查看:145
本文介绍了android-查找最近的位置,以我现在的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的数据库中的一些GPS坐标。

I've some gps coordinate on my database.

我得到我目前的位置,但我不知道我怎样才能找到最近的位置给我,我和这些点之间的距离。

I get my current location but I don't know how can I find the nearest location to me and the distance between me and those point .

您能帮我找到我,这些点之间的最近位置的距离?

Could you help me to find the nearest locations and the distance between me and those points ?

推荐答案

使用这个方法来找到两个点之间的距离的 http://www.geodatasource.com/developers/java

Use this method to find distance between two points http://www.geodatasource.com/developers/java

private double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
      double theta = lon1 - lon2;
      double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
      dist = Math.acos(dist);
      dist = rad2deg(dist);
      dist = dist * 60 * 1.1515;
      if (unit == "K") {
        dist = dist * 1.609344;
      } else if (unit == "N") {
        dist = dist * 0.8684;
        }
      return (dist);
    }

    private double deg2rad(double deg) {
      return (deg * Math.PI / 180.0);
    }

    system.println(distance(32.9697, -96.80322, 29.46786, -98.53506, "M") + " Miles\n");
    system.println(distance(32.9697, -96.80322, 29.46786, -98.53506, "K") + " Kilometers\n");
    system.println(distance(32.9697, -96.80322, 29.46786, -98.53506, "N") + " Nautical Miles\n");

这篇关于android-查找最近的位置,以我现在的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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