-1

In my iPad application i am drawing one rectangle on map using overlay. I have lat/long of one edge as well as length and width of rectangle.
I have some other lat/longs coming from database.

Now how can i get which lat-long from database is inside rectangle?

Thanks,

Ankur
  • 5,086
  • 19
  • 37
  • 62

3 Answers3

3

Solved.

first of all convert four latlons to point using this method :

CGPoint point = [mapView convertCoordinate:location toPointToView:overlayView];

then you have to apply method of point in poly.

Ankur
  • 5,086
  • 19
  • 37
  • 62
2

You can calculate the Distance and if Distance is greater then the current Lat-Long then it is out side otherwise it is inside the circle. You can calculate the Distance using the following lines.

CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

NSLog(@"Distance i meters: %f", [location1 getDistanceFrom:location2]);

[location1 release];

[location2 release];
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
Ankit Vyas
  • 7,507
  • 13
  • 56
  • 89
0

Try this

Please use the below code to get lat and long for touch point.

CGRect r = mapView.bounds;

    float longitudePercent = overlay.point.x / r.size.width;
    float latitudePercent = overlay.point.y / r.size.height;

    CLLocationCoordinate2D coord = mapView.centerCoordinate;
    MKCoordinateSpan span = mapView.region.span;

    float lat = coord.latitude + (span.latitudeDelta/2);
    float lon = coord.longitude - (span.longitudeDelta/2);

Just add your rectangle's length and width in overlay.point.x and overlay.point.y and get other lat and long.

after getting all 4 lat and long make a sql query on database and get related results for that.

Paras Gandhi
  • 823
  • 1
  • 13
  • 28