IOS 7 MKOverlayRenderer not working

I am updating the iOS 6 application for iOS 7 and found that the overlay handlers are completely changed in iOS 7.

We draw a light gray overlay throughout the map. In iOS 6, everything works fine, in iOS 7 we do not get overlays.

In viewDidLoad , I have the following:

 CLLocationCoordinate2D worldCoords[4] = { {90,-180}, {90,180}, {-90,180}, {-90,-180} }; MKPolygon *worldOverlay = [MKPolygon polygonWithCoordinates:worldCoords count:4]; [self.mapView addOverlay:worldOverlay]; 

Then for iOS 6.,.

 - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay { if (![overlay isKindOfClass:[MKPolygon class]]) { return nil; } MKPolygon *polygon = (MKPolygon *)overlay; MKPolygonView *view = [[MKPolygonView alloc] initWithPolygon:polygon]; view.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4]; return view; } 

For iOS 7.,.

 - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay { if (![overlay isKindOfClass:[MKPolygon class]]) { return nil; } MKPolygon *polygon = (MKPolygon *)overlay; MKPolygonRenderer *renderer = [[MKPolygonRenderer alloc] initWithPolygon:polygon]; renderer.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4]; return renderer; } 

Using breakpoints, I verified that the mapView:rendererForOverlay: method is mapView:rendererForOverlay: called and that the renderer returned object has the fillColor property correctly.

Any thoughts on why we don't see overlays?

+6
source share
2 answers

All your code is absolutely right - I connected it to the controller of the test card, and it works fine if I make a small change:

  CLLocationCoordinate2D worldCoords[4] = { {43,-100}, {43,-80}, {25,-80}, {25,-100} }; 

So the problem is not the renderer itself. I believe that this is due to the definition of the 180th Meridian - Apple has made some changes to support the regions covering the 180th Meridian in iOS7. I don’t need it since we focused exclusively on North America, so I missed it, but there is a 2013 WWDC video where they talk about it - see the “What's New in MapKit” section at around 4:42: https: //developer.apple.com/wwdc/videos/

Greetings

+5
source

I tried many times and finally found a world map covered in all manner. Apple does not know how to use sdk, you have to add two polygons, the world map will be divided into two parts. And added to the overlay. These two parts define a boundary:

  var ccoodsW = new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(){ Latitude = 85.9809906974076,Longitude = -179.999999644933 }, new CLLocationCoordinate2D(){ Latitude = -80.9793991796858,Longitude = -179.999999644933}, new CLLocationCoordinate2D(){ Latitude = -80.97939920061767,Longitude = 0}, new CLLocationCoordinate2D(){ Latitude = 85.9809906974076 ,Longitude = 0} }; var ccoodsE = new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(){ Latitude = 85.9809906974076,Longitude = 0 }, new CLLocationCoordinate2D(){ Latitude = -80.9793991796858,Longitude = 0}, new CLLocationCoordinate2D(){ Latitude = -80.97939920061767,Longitude = 179.999999644933}, new CLLocationCoordinate2D(){ Latitude = 85.9809906974076 ,Longitude = 179.999999644933} }; 

BTW: I am using xamarin for ios

+1
source

Source: https://habr.com/ru/post/954191/


All Articles