-
-
Save tommypeps/f8b8347b32f12007ac64f7d33061b5a9 to your computer and use it in GitHub Desktop.
Add polygon overlay to mapkit iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay | |
{ | |
if ([overlay isKindOfClass:[MKPolygon class]]) | |
{ | |
MKPolygonView* aView = [[MKPolygonView alloc]initWithPolygon:(MKPolygon*)overlay]; | |
aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2]; | |
aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7]; | |
aView.lineWidth = 3; | |
return aView; | |
} | |
return nil; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
// Adds a polygon over the commuter parking in front of the library | |
CLLocationCoordinate2D libComPark[4]; | |
libComPark[0] = CLLocationCoordinate2DMake(33.874689,-98.520148); | |
libComPark[1] = CLLocationCoordinate2DMake(33.87469,-98.519692); | |
libComPark[2] = CLLocationCoordinate2DMake(33.874314,-98.519687); | |
libComPark[3] = CLLocationCoordinate2DMake(33.874316,-98.520146); | |
MKPolygon *polLibcomPark = [MKPolygon polygonWithCoordinates:libComPark count:4]; | |
[msuMap addOverlay:polLibcomPark]; | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Declare an array that will hold the coordinates within the viewDidLoad function/method. Then fill the array with the coordinates. Then define a MKPolygon pointer that will use that array. Last, add the overlay to the map. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment