Adding distance to a GPS coordinate

后端 未结 5 1107
南旧
南旧 2020-11-28 05:32

I\'m trying to generate some points at random distances away from a fixed point using GPS.

How can I add distance in meters to a GPS coordinate? I\'ve looked at UTM

5条回答
  •  粉色の甜心
    2020-11-28 05:39

    If you want to go east or north or west or south you can use this:

    @SuppressLint("DefaultLocale")
    public static double go_mock_loc(double xx_lat,double xx_long,double xx_dinstance,String Direction)
    {
    //  double xx_lat= 45.815005; 
    //  double xx_long= 15.978501;
    
    //  int xx_dinstance=500;
    
        int equator_circumference=6371000;
        int polar_circumference=6356800;
    
        double m_per_deg_long =  360 / polar_circumference;
        double rad_lat=(xx_lat* (Math.PI) / 180);
        double m_per_deg_lat = 360 / ( Math.cos(rad_lat) * equator_circumference);
    
        double deg_diff_long = xx_dinstance * m_per_deg_long;
        double deg_diff_lat  = xx_dinstance * m_per_deg_lat; 
    
    
        double xx_north_lat = xx_lat + deg_diff_long;
        //double xx_north_long= xx_long;
        double xx_south_lat = xx_lat - deg_diff_long;
        //double xx_south_long= xx_long;
    
        //double xx_east_lat = xx_lat;
        double xx_east_long= xx_long + deg_diff_lat;  
        //double xx_west_lat = xx_lat;
        double xx_west_long= xx_long - deg_diff_lat;
    
        if (Direction.toUpperCase().contains("NORTH")) {
            return xx_north_lat;
        } else if (Direction.toUpperCase().contains("SOUTH"))
        {
            return xx_south_lat;
        } else if (Direction.toUpperCase().contains("EAST"))
        {
            return xx_east_long;
        } else if (Direction.toUpperCase().contains("WEST"))
        {
            return xx_west_long;
        }
        else 
            return 0; 
    
    }
    

提交回复
热议问题