计算定位距离公式

cocos2d-x技术群新群:117871561
c++技术交流群:593010226
第一种:高德定位的接口

import com.amap.api.maps2d.AMapUtils;
import com.amap.api.maps2d.model.LatLng;
    public String metersBetweenLocation(String loParam)
    {
        String msg = "0";
        try 
        {
            JSONObject jObject = new JSONObject(loParam);
            double myLatitude = jObject.getDouble("myLatitude");
            double myLongitude = jObject.getDouble("myLongitude");
            
            double otherLatitude = jObject.getDouble("otherLatitude");
            double otherLongitude = jObject.getDouble("otherLongitude");
            
            LatLng my2d = new LatLng(myLatitude, myLongitude);
            LatLng or2d = new LatLng(otherLatitude, otherLongitude);
            BigDecimal db = new BigDecimal(AMapUtils.calculateLineDistance(my2d, or2d));
            msg = db.toPlainString();
        } 
        catch (JSONException e) 
        {
            e.printStackTrace();
        }
        return msg;
    }


第二种:

#include "math.h"
#define COVER 180
#define PAI  3.1415926
#define RADIUS 6366000
#define M      1000

void AddressManager::compute()
{


                    double pk = (double)(COVER / PAI);

                    //计算参数
                    double      a1 = m_LocationData[i].lng / pk;
                    double a2 = m_LocationData[i].lat / pk;
                    double b1 = m_LocationData[j].lng / pk;
                    double b2 = m_LocationData[j].lat / pk;

                    //计算后的参数进行计算
                    double t1 = cos(a1)*cos(a2)*cos(b1)*cos(b2);
                    double t2 = cos(a1)*sin(a2)*cos(b1)*sin(b2);
                    double t3 = sin(a1)*sin(b1);
                    double tt = acos(t1 + t2 + t3);
                    double result = RADIUS * tt /*/ M*/;

        
    }

你可能感兴趣的:(计算定位距离公式)