Android: How to: determine if a Location is between LocationA and LocationB in Android way?
<p>How do you determine if LocationX is between LocationA and LocationB? Is there an Android way to determine it?</p>

<p><strong>UPDATE</strong>
I am asking here if LocationX is on the BuildingA or on the BuildingB. I have the upper left and lower right coordinates of the two buildings.</p>

<p><strong>UPDATE2</strong>
Let say LocationX is a person. Main goal is to determine if that person is on the BuildingA or is on the BuildingB.</p>

<p><strong>UPDATE3</strong>
Let say that BuildingA and BuildingB are rectangle/square. so we just need upper left and lower right latitude and longitude.</p>

<p><strong>UPDATE4</strong>
Let me to add code snippet from @ligi 's response. But the code below is failed.</p>

<pre><code>Location locationA = new Location("A");
locationA.setLatitude(35.70217034224572);
locationA.setLongitude(139.74359443782043);
Location locationB = new Location("B");
locationB.setLatitude(35.69994863045598);
locationB.setLongitude(139.74633029101562);
Location locationX = new Location("X");
// TODO result: X:169.661 Y:347.359
locationX.setLatitude(35.70066307001967);
locationX.setLongitude(139.74450102446747);

//distanceAB &gt; (distanceXA + distanceXB - threshold)
float threshold = 0f;
float distanceAB = locationA.distanceTo(locationB);
float distanceXA = locationX.distanceTo(locationA);
float distanceXB = locationX.distanceTo(locationB);
boolean result = distanceAB &gt; (distanceXA + distanceXB - threshold);
assertTrue(result);
</code></pre>
