Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:26:32+00:00 2026-06-04T05:26:32+00:00

I have got CLLocation object which contains current location of user and I have

  • 0

I have got CLLocation object which contains current location of user and I have got 4 lat/long pairs for each corner of a rectangle which can be angled. Now I want to check whether CLLocation coordinates are within that rectangle.

Following are the coordinates of the rectangle

#define NorthEast_LAT 51.514894
#define NorthEast_LNG -0.135306
#define SouthEast_LAT 51.514831
#define SouthEast_LNG -0.135153
#define NorthWest_LAT 51.514719
#define NorthWest_LNG -0.135858
#define SouthWest_LAT 51.514556
#define SouthWest_LNG -0.135714

I have tried following code but I think it will only work when angle of rectangle is 0 deg.

 BOOL withinRect = [delegate.CLController latlngWithInBox:location 
                                                    point1:CLLocationCoordinate2DMake(NorthEast_LAT, NorthEast_LNG) 
                                                    point2:CLLocationCoordinate2DMake(SouthEast_LAT, SouthEast_LNG) 
                                                    point3:CLLocationCoordinate2DMake(NorthWest_LAT, NorthWest_LNG)
                                                    point4:CLLocationCoordinate2DMake(SouthWest_LAT, SouthWest_LNG)];

 - (BOOL) latlngWithInBox:(CLLocation *)position point1:(CLLocationCoordinate2D)point1 point2:(CLLocationCoordinate2D)point2 point3:(CLLocationCoordinate2D)point3 point4:(CLLocationCoordinate2D)point4 {

if (position.coordinate.latitude >= point3.latitude && position.coordinate.latitude <= point2.latitude
    && position.coordinate.longitude >= point3.longitude && position.coordinate.longitude <= point2.longitude) {
    return YES;
}
return NO;

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:26:34+00:00Added an answer on June 4, 2026 at 5:26 am
    - (BOOL) latlngWithInBox:(CLLocation *)position point1:(CLLocationCoordinate2D)point1 point2:(CLLocationCoordinate2D)point2 point3:(CLLocationCoordinate2D)point3 point4:(CLLocationCoordinate2D)point4 {
        //&& position.coordinate.latitude >= [[point4 objectAtIndex:0] floatValue] && position.coordinate.latitude <= [[point1 objectAtIndex:0] floatValue] && position.coordinate.longitude <= [[point4 objectAtIndex:1] floatValue] && position.coordinate.longitude >= [[point1 objectAtIndex:1] floatValue]
        if (PointInTriangle(position.coordinate, point1, point2, point3) || PointInTriangle(position.coordinate, point2, point3, point4)) {
            return YES;
        }
        return NO;
    }
    
    float sign(CLLocationCoordinate2D p1, CLLocationCoordinate2D p2, CLLocationCoordinate2D p3)
    {
        return (p1.longitude - p3.longitude) * (p2.latitude - p3.latitude) - (p2.longitude - p3.longitude) * (p1.latitude - p3.latitude);
    }
    
    bool PointInTriangle(CLLocationCoordinate2D pt, CLLocationCoordinate2D v1, CLLocationCoordinate2D v2, CLLocationCoordinate2D v3)
    {
        bool b1, b2, b3;
    
        b1 = sign(pt, v1, v2) < 0.0f;
        b2 = sign(pt, v2, v3) < 0.0f;
        b3 = sign(pt, v3, v1) < 0.0f;
    
    //    NSLog(@"b1-%@", [NSNumber numberWithBool:b1]);
    //    NSLog(@"b2-%@", [NSNumber numberWithBool:b2]);
    //    NSLog(@"b3-%@", [NSNumber numberWithBool:b3]);
    
        return ((b1 == b2) && (b2 == b3));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got method which is using Assembly.LoadFrom(...) statement and returns the supported cultures
I've got an sqlite db with long and lat of shops and I want
I have got a class which is called BaseCore which just runs all the
I have got script which generates some graphic and returns it as a result,
I've got a class which uses the context management protocol to have a silent
We have got loads of options for php + MySQL + Apache combo... Which
I have got a python script which is creating an ODBC connection. The ODBC
I have got a List<Problem> which I want to export to a column based
I have got a problem with a CLLocation. I wanted to know the distance
I have got a problem on casting an object to one of it's base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.