Quote:
Originally Posted by Duncan C
What do you mean by the difference between 2 regions? Do you want to calculate the map distance between the center of two map regions?
To do that, get the center coordinate of each region, and create a CLLocation object for each (using the method initWithLatitude:longitude
Once you have 2 CLLocation objects, you can send one of them the message distanceFromLocation: to calculate the distance between the 2 locations.
|
Hi Duncan.Thanks For Reply.I am really happy that you answer my question.As you asked what is difference of region.So, I am giving you some code.I hope that will make my question very clear.
MKCoordinateRegion mapregion1,mapregion2;
MKMapRect mapRect1 = [self mapRectForCoordinateRegion:mapregion1];
MKMapRect mapRect2 = [self mapRectForCoordinateRegion:mapregion2];
MKMapRect maprectintersection = MKMapRectIntersection(mapRect1, mapRect2);
maprectintersection is a common rectangle part between two region that i can find but i want to difference between them.I hope i made myself clear.
//Method will convert map region into maprect
- (MKMapRect)mapRectForCoordinateRegion

MKCoordinat eRegion)coordinateRegion
{
CLLocationCoordinate2D topLeftCoordinate =
CLLocationCoordinate2DMake(coordinateRegion.center .latitude
+ (coordinateRegion.span.latitudeDelta/2.0),
coordinateRegion.center.longitude
- (coordinateRegion.span.longitudeDelta/2.0));
MKMapPoint topLeftMapPoint = MKMapPointForCoordinate(topLeftCoordinate);
CLLocationCoordinate2D bottomRightCoordinate =
CLLocationCoordinate2DMake(coordinateRegion.center .latitude
- (coordinateRegion.span.latitudeDelta/2.0),
coordinateRegion.center.longitude
+ (coordinateRegion.span.longitudeDelta/2.0));
MKMapPoint bottomRightMapPoint = MKMapPointForCoordinate(bottomRightCoordinate);
MKMapRect mapRect = MKMapRectMake(topLeftMapPoint.x,
topLeftMapPoint.y,
fabs(bottomRightMapPoint.x-topLeftMapPoint.x),
fabs(bottomRightMapPoint.y-topLeftMapPoint.y));
return mapRect;
}
Thanks In Advance.
Nitin.