2014-01-30 2 views
0

MKMapView에 삼각형 폴리곤이있어서 매우 빠르게 다시 그리거나 전화의 특정 위치에 고정하려고합니다.iOS MKMapView가지도에 오버레이를 재빨리 다시 그립니다.

이 다각형은 항상 휴대 전화의 상단을 가리키지 만지도 자체는 제공된 제목으로 회전합니다. 현재 내가 가진 유일한 방법은 오버레이를 제거한 다음 다시 추가하는 것입니다. 이 문제는 매우 고르지입니다.

다음 아이디어는 맵 위에 삼각형 이미지를 추가하고 필요에 따라 맵의 크기를 조정하는 것이 었습니다.이 삼각형 이미지는 맵 오버레이로 추가 될 때 폴리곤이 무엇인지를 정확하게 시각화 한 것입니다. 이 은 거의이지만 작동은 정확하지 않습니다. 어떤 이유로 위도 줌 레벨의 변경 사항 및 기타 문제에 거의 응답하지 않습니다. 이것에 대한

내 방법은 다음과 같습니다에 관계없이 항상지도 회전 화면 상단을 가리키는 오버레이를 유지하는 방법은

- (void)setMapVisibleRect { 
    //we have to mock the heading to 0 so that the distances show up in lat/long correctly 
    //create a new instance of the cone model with a fake heading of 0 for calculations 
    ConePolygonModel *conePolygonModel = [[ConePolygonModel alloc] init:[self.userLocationModel getLocation].coordinate 
                  withHeading:0 
                withLatLongMultiplier:[self.conePolygonModel getLatLongMultiplier] 
               withDistanceMultiplier:[self.conePolygonModel getDistanceMultiplier]]; 
    //reset the map heading to 0 
    [self.mapView.camera setHeading:0]; 

    //top left setup 
    CLLocationCoordinate2D topLeftCoordinate; 
    topLeftCoordinate.latitude = [[[conePolygonModel getXCoordinates] objectAtIndex:1] doubleValue]; 
    topLeftCoordinate.longitude = [[[conePolygonModel getYCoordinates] objectAtIndex:1] doubleValue]; 

    CLLocation *topLeftLocation = [[CLLocation alloc] initWithLatitude:topLeftCoordinate.latitude longitude:topLeftCoordinate.longitude]; 

    //top right setup 
    CLLocationCoordinate2D topRightCoordinate; 
    topRightCoordinate.latitude = [[[conePolygonModel getXCoordinates] objectAtIndex:2] doubleValue]; 
    topRightCoordinate.longitude = [[[conePolygonModel getYCoordinates] objectAtIndex:2] doubleValue]; 

    CLLocation *topRightLocation = [[CLLocation alloc] initWithLatitude:topRightCoordinate.latitude longitude:topRightCoordinate.longitude]; 

    //center setup 
    CLLocationCoordinate2D topCenterCoordinate = [conePolygonModel midpointBetweenCoordinate:topLeftCoordinate andCoordinate:topRightCoordinate]; 

    CLLocation *topCenterLocation = [[CLLocation alloc] initWithLatitude:topCenterCoordinate.latitude longitude:topCenterCoordinate.longitude]; 

    //set distances 
    CLLocationDistance latitudeDistance = [topLeftLocation distanceFromLocation:topRightLocation]; 
    CLLocationDistance longitudeDistance = [topCenterLocation distanceFromLocation:[self.userLocationModel getLocation]]; 

    //set the map zoom 
    NSLog(@"zoom levels: %f %f", latitudeDistance, longitudeDistance); 
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance([self.userLocationModel getLocation].coordinate, latitudeDistance, longitudeDistance); 
    [self.mapView setRegion:viewRegion]; 

    //move the map to the actual heading 
    [self.mapView.camera setHeading:self.currentHeading]; 
} 

있습니까? 오버레이가 화면에서 항상 같은 크기를 차지하도록지도를 확대하는 것도 좋지만 다른 지점만큼 중요하지는 않습니다.

+0

두 번 확인하려면 사용자가지도를 조작하는 방법에 관계없이 삼각형이 항상 사용자 화면에서 동일한 물리적 크기를 유지하고 동일한 회전을 유지하게해야합니까? –

답변

0

오버레이 대신 MKAnnotationView로 구현하십시오. 삼각형이 항상 같은 크기와 방향을 갖지만 맵의 좌표계의 특정 지점에 계속 연결되기를 바랍니다.

가장 간단한 방법은 PNG 파일을 만들고 mapView:viewForAnnotation: 대리자 메서드에서 MKAnnotationViewimage 속성에 UIImage를 할당하는 것입니다. 또는 코어 그래픽을 사용하여 프로그래밍 방식으로 삼각형을 그려서 런타임에 UIImage로 바꿀 수 있습니다. Core Graphics를 사용하여 이미지를 한 번 렌더링하고 UIImage 객체에 대한 참조를 유지하면 viewForAnnotation이 호출 될 때마다 다시 그릴 필요가 없습니다.

관련 문제