Sterling Duchess
Sterling Duchess

Reputation: 2080

Selecting all entries between 4 grid locations

So I have a table and this table has two attibutes latitude and longitude both of type double. Now I have some idea about how to do a SELECT statement to get all the required rows but don't know how to put this togather or if it will be correct.

Basically I have an android map like so:
enter image description here
Each dot represents one edge of phones screen. Now the coordiantes come in form of Location object containing two attributes Latitude and Longitude.

How would I select all entries that have Longitude and Latitude inside this grid. My first try was

SELECT * FROM table WHERE (topLeftLatitude < latitude < topRightLatitude) AND (topLeftLongitude < longitude < topRightLongitude)

But I'm thinking this will only select the ones that are in horizontal line or ? After 10h resolving the DB issue I'm pretty confused here.

Upvotes: 0

Views: 46

Answers (1)

Rolf ツ
Rolf ツ

Reputation: 8781

To select something within a square in general you need four AND statements, not sure if this is true for the Google maps API but I would guess something like this:

SELECT * FROM table WHERE (latitude > topLeftLatitude) AND (latitude < topRightLatitude) AND (topLeftLongitude > longitude) AND (bottomLeftLongitude < longitude)

Correct me if I'm wrong

Upvotes: 1

Related Questions