Question

I want to develop an app that, at first, submit an object location "With Direction" so that when moving again in this street in later time "in the same direction" I can detect that and tell the user you are in the same direction of that object and you are xyz meters far.

object location and distance will be detected using the location provider service weather it is GPS or another one.

my problem now is the direction , how to submit object direction so that later I can know that i'm in the same direction of the street.

Thanks in advance

Était-ce utile?

La solution

To find direction between two points you can use one of the following:

1-If using Location objects:

Location initialPoint = new Location("");
initialPoint.setLatitude(initialLatitude);
initialPoint.setLongitude(initialLongitude);

Location finalPoint = new Location("");
finalPoint .setLatitude(finalLatitude);
finalPoint .setLongitude(finalLongitude);

float direction = initialPoint.bearingTo(finalPoint);

2-Using static Location method

private float results2[] = new float[2];
Location.distanceBetween(initialLatitude, initialLongitude, finalLatitude, finalLongitude, results);
float direction = reasults[1];

Regards

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top