0

I am working with mapkit in Xcode 5.1 and am trying to display the map scale in regionDidChangeAnimated. I have no idea now to accomplish this though. I tried to look around and was unsuccessful. Any ideas?

EDIT:

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

CGPoint nePoint = CGPointMake(self.mapView.bounds.origin.x + mapView.bounds.size.width, mapView.bounds.origin.y);
CGPoint swPoint = CGPointMake((self.mapView.bounds.origin.x), (mapView.bounds.origin.y + mapView.bounds.size.height));

CLLocationCoordinate2D neCoord;
neCoord = [self.mapView convertPoint:nePoint toCoordinateFromView:self.mapView];
CLLocationCoordinate2D swCoord;
swCoord = [self.mapView convertPoint:swPoint toCoordinateFromView:self.mapView];

CLLocationDistance distance = [neCoord distanceFromLocation:swCoord];
}

Any reason why I am getting an error with the last line, CLLocationDistance?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
bolencki13
  • 89
  • 1
  • 8
  • The distanceFromLocation method is in the CLLocation class. neCoord is a CLLocationCoordinate2D struct (not a CLLocation). To create a CLLocation from a CLLocationCoordinate2D, see http://stackoverflow.com/questions/2318547/cllocationcoordinate2d-to-cllocation. –  Jul 19 '14 at 11:56

1 Answers1

0

Use the methods that translate between the coordinates on the map and the points on the map view, such as convertPoint:toCoordinateFromView:. Use the edge points of your view for this.

Now you have the coordinates - you can calculate the distances between the points with CLLocation's distanceFromLocation:. You can make some assumptions about the width of your view based on the physical properties of, day an iPhone or iPad and calculate the scale.

Mundi
  • 79,884
  • 17
  • 117
  • 140