-1

I have a SQLite database which stores latitude and longitude. I have to find if the users current location is between the Latitude and Longitude(Which is stored in Database) or not.

I been looking for a while to find a solution for this problem but couldn't get it. Most of them are related with the distance calculation.

How to find the current location(obtained in the app) is between the Latitude and Longitude(Which is stored in SQLite Database)?

vinothp
  • 9,939
  • 19
  • 61
  • 103

2 Answers2

1

I am not sure if you exactly want but what i think

what you have : two geographical point (two pair of attitude and longitude )

what you want : calculate the adjoining regions covered between the two geo points , and check if the user is within that are

for that what you can do is :

1 : suppose the two points are diameteric terminals of a circle and search if the user is within this circle , like this Image

enter image description here

this approach might make you search a little irrelavant region

2 : suppose the two point are two ends of a straight line , consider a distance , say 50 km , on both sides , and search the 100 km wide strip from point A to point B like this Image

enter image description here

1

Assume you have two locations a and b and your current location c.

   C  
  / \  
 A---B

You can use the dotproduct to calculate if c is between a and b:

If the dotproduct of two vectors is >0, the degrees between these vectors is <90°.

Know you need two calculations like this:

if(Vector(AB) * Vector(AC) > 0 && Vector(BC) * Vector(BA) > 0)
    // your location is between

You can also look here and here for more details.

Community
  • 1
  • 1
Steve Benett
  • 12,843
  • 7
  • 59
  • 79