좌표를 기준으로 MKPolygon
초로 MKMapView
을 만들었습니다. 지도에 여러 개의 다각형이 있습니다 (응용 프로그램으로 다시 작성하는 예는 here을 참조하십시오).MKPolygon ontouch detailview
사용자가 다각형을 만졌을 때 위치에 대한 정보가 포함 된 팝업보기가 열립니다. 이 정보는 현재 좌표와 함께 plist 파일 안에 저장됩니다.
지금까지 내가 터치 이벤트를 얻고 로그에 다각형을 만졌을 때 인쇄 할 수 있습니다.
I가 가지고있는 질문 :
가 MKPolygonView
사용자가 핀 자세한 내용은 도청이 현재 위치에 대한 팝업 번 MKAnnotationView
처럼 사용할 수 있습니까?
다각형보기에서도 동일한 작업을 수행하려고합니다. 만졌을 때, 사용자는 plist에 저장된 위치에 대한 더 많은 정보를 볼 수 있습니다. 가능하다면 어떻게 작동시키는 것이 가장 좋은 방법일까요?
현재 코드는 아래와 같습니다.
#import "outagemapViewController.h"
#import "MyAnnotation.h"
#import "WildcardGestureRecognizer.h"
#define METERS_PER_MILE 46309.344
@interface outagemapViewController()
@end
@implementation outagemapViewController
- (void)viewDidLoad {
outages = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"outages"ofType:@"plist"]];
for (NSDictionary *coloredAreas in outages) {
coordinateData = coloredAreas[@"coords"];
test = coloredAreas[@"outages"];
NSLog(@"test %@", test);
coordsLen = [coordinateData count];
NSLog(@"coords %d", coordsLen);
CLLocationCoordinate2D coords[coordsLen];
for (i=0; i < coordsLen; i++) {
NSString *lat = coordinateData[i];
NSArray *latt = [lat componentsSeparatedByString:@","];
double latitude = [[latt objectAtIndex:0] doubleValue];
double longitude = [[latt objectAtIndex:1] doubleValue];
coords[i] = CLLocationCoordinate2DMake(latitude, longitude);
}
MKPolygon* poly2 = [MKPolygon polygonWithCoordinates:coords count:coordsLen];
[email protected]"test";
[self.mapView addOverlay:poly2];
}
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
{
if ([overlay isKindOfClass:[MKPolygon class]])
{
MKPolygonView* aView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];
int numbers = [test intValue];
if(numbers >= 10){
aView.fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.6];
aView.strokeColor = [[UIColor greenColor] colorWithAlphaComponent:1.0];
aView.lineWidth = 3;
}else if(numbers < 10){
aView.fillColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:1.0];
aView.lineWidth = 3;
}
return aView;
}
return nil;
}
}
-(void)viewWillAppear:(BOOL)animated{
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 35.20418;
zoomLocation.longitude = -89.86862;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
[_mapView setRegion:viewRegion animated:YES];
WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
tapInterceptor.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.mapView];
CLLocationCoordinate2D coord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
MKMapPoint mapPoint = MKMapPointForCoordinate(coord);
for (id overlay in self.mapView.overlays)
{
if ([overlay isKindOfClass:[MKPolygon class]])
{
MKPolygon *poly = (MKPolygon*) overlay;
id view = [self.mapView viewForOverlay:poly];
if ([view isKindOfClass:[MKPolygonView class]])
{
MKPolygonView *polyView = (MKPolygonView*) view;
CGPoint polygonViewPoint = [polyView pointForMapPoint:mapPoint];
BOOL mapCoordinateIsInPolygon = CGPathContainsPoint(polyView.path, NULL, polygonViewPoint, NO);
if (mapCoordinateIsInPolygon) {
// debug(@"hit!");
NSLog(@"hit");
} else {
NSLog(@"miss");
}
}
}
}
};
[self.mapView addGestureRecognizer:tapInterceptor];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
의 새로운 기능 : 마지막으로
, 오버레이이 도청 중단 개체를 얻을 수
viewForOverlay
에서와 같이 동일한 방법을 사용 특정 질문? 히트 감지가 작동합니까? – Anna주석과 마찬가지로 내장 된 설명 선보기가 없습니다. 사용자 정의 UIView를 만들고 addSubview 또는 사용자 정의 UIViewController를 수행하고 present/push해야합니다. – Anna
아. 고맙습니다. 나는 어제이 사실에 대해 좌절했기 때문에 나는 진짜 질문을하는 것을 잊었다. 폐쇄 된 상태에서도 1 + 당신을 위해. – Dwill