How do you clone your own Location, and then add some extra metres towards a desired direction?
Right now my android app can get the azimut, and my GPS location, and I hardcoded the desired distanct for an example, 10 metres.
Then my app should create a new Location, exactly 10 metres ahead where im facing.
So if my position is: longitude 17.537200603552526, latitude 25.70358496181195
and i want to it to move 8 metres directly towards north, and 2 metres directly towards east.
Would the new longitude and latitude look like:
current longitude + 0.00008 , current latitude + 0.00002
Heres some of my code to calculate the gradient and the new location:
public double[] calculateXYLength(double[] vals, double distance)
{
double x = vals[0];
double y = vals[1];
if (vals[0] < 0)
{
x = x * -1;
}
if (vals[1] < 0)
{
y = y * -1;
}
// Log.d("lengths", "K = " + distance + " / (" + x + " + " + y + " )" );
double k = distance / (x + y);
// Log.d("lengths", "vals[0]: " + vals[0] + " vals[1]: " + vals[1]);
// Log.d("lengths", "x: " + (vals[0] * k) + " y: " + (vals[1] * k) +
// " k: " + k);
return new double[] { (vals[0] * k), (vals[1] * k) };
}
Notice the vals is the gradient i already calculated, and the result i'm returning i'm going to use to add to my new location point.
Location newPosition = currentPosition
newPosition.setLongitude(myPosition.getLongitude() + val[0]);
newPosition.setLatitude(myPosition.getLatitude() + val[1]);
But the thing is, I don't get the desired distance between these two locations.. And I can't figure out why. How do I add the desired distance on the latitude/longitude?
Thanks, Johan