如何calulate通过给经纬度最近位置 [英] How to calulate nearest locations by giving latitude and longitude

查看:161
本文介绍了如何calulate通过给经纬度最近位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  geopoints之间

Possible Duplicate:
Distance between geopoints

我有一些纬度和经度,我需要找到从我的当前位置最近的位置与这些纬度和经度

I have some latitudes and longitudes and i need to find the nearest locations with these latitude and longitudes from my current place

推荐答案

试试这个,

public class getDistanceList 
{
/**
 * 
 * @param lat1 Latitude of the First Location
 * @param lng1 Logitude of the First Location
 * @param lat2 Latitude of the Second Location
 * @param lng2 Longitude of the Second Location
 * @return distance between two lat-lon in float format
 */

public static float distFrom (float lat1, float lng1, float lat2, float lng2 ) 
{
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2-lat1);
    double dLng = Math.toRadians(lng2-lng1);
    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
    Math.sin(dLng/2) * Math.sin(dLng/2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

这篇关于如何calulate通过给经纬度最近位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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