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];
}
マップの回転に関係なく、オーバーレイを常に画面の上部に向ける方法はありますか? オーバーレイが画面上で常に同じサイズになるようにマップをズームすることも良いですが、他のポイントほど重要ではありません。