0

I have very limited experience with GIS systems.

I am writing an iOS application which will show a number of places on a map.

At my back end, I store the 'places' in the format:

Placename - string
Lat - decimal
Lon - decimal

I determine the current viewable area of the map (on the device) using the following Objective-C code:

MKMapRect mRect = self.mapView.visibleMapRect;
MKMapPoint neMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), mRect.origin.y);
MKMapPoint swMapPoint = MKMapPointMake(mRect.origin.x, MKMapRectGetMaxY(mRect));
MKMapPoint nwMapPoint = MKMapPointMake(swMapPoint.x, neMapPoint.y);
MKMapPoint seMapPoint = MKMapPointMake(neMapPoint.x, swMapPoint.y);
CLLocationCoordinate2D neCoord = MKCoordinateForMapPoint(neMapPoint);
CLLocationCoordinate2D swCoord = MKCoordinateForMapPoint(swMapPoint);
CLLocationCoordinate2D nwCoord = MKCoordinateForMapPoint(nwMapPoint);
CLLocationCoordinate2D seCoord = MKCoordinateForMapPoint(seMapPoint);
NSLog(@"NW: %f, %f", nwCoord.latitude,nwCoord.longitude);
NSLog(@"NE: %f, %f", neCoord.latitude,neCoord.longitude);
NSLog(@"SE: %f, %f", seCoord.latitude,seCoord.longitude);
NSLog(@"SW: %f, %f", swCoord.latitude,swCoord.longitude);

This will give me an output of:

NW: 54.558793, -1.268541
NE: 54.558793, -1.254808
SW: 54.549659, -1.268541
SE: 54.549659, -1.254808

I want to pass the box coordinates to my backend system, which will return me information on any 'places' within the box.

What is the math to determine if a 'place' actually falls within the bounds of the box?

0

1 Answer 1

3

As is typical after asking my question, I think I found a solution.

Based on the NW and SW point, the following pseudo code, will return me items within the bounding box.

Lat <= NW.LAT 
AND 
Lat >= SW.LAT
AND 
Long <= NE.LON 
AND 
Long >= SW.LON

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.