andypower
9/24/2015 - 9:03 AM

Shift the lon lat using a random distance between 1Km

Shift the lon lat using a random distance between 1Km

    /**
     *
     * @param lon
     * @param lat
     * @return Shift the lon lat using a random distance between 1Km
     */
    private GeoPoint shiftLonLatPoint(double lat, double lon) {
        //Earth’s radius, sphere
        final double earthRadius = 6378137;
        //offsets in meters
        Random rand = new Random();
        double dn = (rand.nextDouble() - 0.5d) * 2000; //Returns a number between [-1000, 1000]
        double de = (rand.nextDouble() - 0.5d) * 2000;
//        final double dn = rand.nextInt(1001);
//        final double de = rand.nextInt(1001);
//        lon += rand.nextDouble() * 0.001;
//        lat += rand.nextDouble() * 0.001;
        //Coordinate offsets in radians             
        final double dLat = dn / earthRadius;
        final double dLon = de / (earthRadius * Math.cos(Math.PI * lat / 180));
        //OffsetPosition, decimal degrees
        final double latO = lat + dLat * 180 / Math.PI;
        final double lonO = lon + dLon * 180 / Math.PI;
        return new GeoPoint(latO, lonO);
//        return new GeoPoint(lat, lon);
    }