在iPhone 3GS中的“地图”应用程序,你可以点击这通常表明你的立场两次,蓝点获得什么样子从头灯光束中的图标,基本上显示你所面对的地图上的方向和旋转图像因此。
是使用MapKit的MapView这个选项可用?
我知道,我可以让我的标题喜欢的东西
- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {
//如果精度是有效的,过程中的事件。
if (newHeading.headingAccuracy > 0) {
CLLocationDirection theHeading = newHeading.magneticHeading;
...
}
}
但我不知道如何让Mapkit那可爱的前大灯效果,似乎没有被任何文件。
有任何想法吗?
我发现了一个解决方案:
我旋转利用现有的标题信息与地图
[mapView setTransform:CGAffineTransformMakeRotation(heading.magneticHeading * M_PI / -180.0)];
因此,“束”总是指向该装置的顶部。我现在只是在地图的顶部显示的ImageView并改变其位置的LocationManager:didUpdateToLocation:从地点:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// scroll to new location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 2000, 2000);
[self.mapView setRegion:region animated:YES];
// set position of "beam" to position of blue dot
self.headingAngleView.center = [self.mapView convertCoordinate:newLocation.coordinate toPointToView:self.view];
// slightly adjust position of beam
self.headingAngleView.frameTop -= self.headingAngleView.frameHeight/2 + 8;
}
由此frameTop和frameHeight是frame.origin.y和frame.size.height快捷方式。这是不理想的,有时缺乏一点点当点改变它的位置,但我很高兴与解决方案B / C它的工作原理。
看看我的开放源代码框架MTLocation其中,这一切(和很多为你等凉的相关地图,东西):
其他答案的旋转逻辑都不错,但是依靠外景经理的委托方法不会导致一个很好的解决方案。在“束”的形象很少会在同一个地方的蓝点,并会反弹围了很多。
最好的办法是去蓝点视图参考,并添加“束”的形象作为一个子视图到它。我去,这是一个方形的光束图像,与梁往上顶和透明度周围的一切。试想一下,蓝点在图像的中心之中。
// An MKMapViewDelegate method. Use this to get a reference to the blue dot annotation view as soon as it gets added
- (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView *annotationView in views) {
// Get the user location view, check for all of your custom annotation view classes here
if (![annotationView isKindOfClass:[MKPinAnnotationView class]])
{
self.userLocationAnnotationView = annotationView;
gotUsersLocationView = YES;
}
}
}
// Adds the 'viewPortView' to the annotation view. Assumes we have a reference to the annotation view. Call this before you start listening to for heading events.
- (void)addViewportToUserLocationAnnotationView {
TTDASSERT(self.userLocationAnnotationView != nil);
if (self.userLocationAnnotationView == nil) {
// No reference to the view, can't do anything
return;
}
if (self.viewPortView == nil) {
self.viewPortView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map_viewport.png"]] autorelease];
}
[self.userLocationAnnotationView addSubview:self.viewPortView];
[self.userLocationAnnotationView sendSubviewToBack:self.viewPortView];
self.viewPortView.frame = CGRectMake((-1 * self.viewPortView.frame.size.width/2) + self.userLocationAnnotationView.frame.size.width/2,
(-1 * self.viewPortView.frame.size.height/2) + self.userLocationAnnotationView.frame.size.height/2,
self.viewPortView.frame.size.width,
self.viewPortView.frame.size.height);
}
添加用户跟踪模式也有帮助。我知道我迟到了,但可能对其他开发商像我这样的帮助:)
self.mapView.userTrackingMode = RMUserTrackingModeFollowWithHeading;
斯威夫特3实施
mapView.userTrackingMode = MKUserTrackingMode.followWithHeading
我能想到一个方法,虽然我还没有实现,但可能你有点帮助。
didUpdateHeading
使用x和y的值,以计算方向的角度。请张贴在上面的方法您的建议/变化。