好吧,这实际上是一个线程中的三个不同的问题:
1)我正在使用:
- (void)viewDidLoad
{
[super viewDidLoad];
[mapView setFrame :CGRectMake(-100,-100,520,520)];
[mapView setAutoresizesSubviews:true];
mapView.showsUserLocation = YES;
locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
[locManager startUpdatingLocation];
[locManager startUpdatingHeading];
[bt_toolbar setEnabled:YES];
}
- (IBAction) CreatePicture
{
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(mapView.userLocation.coordinate.latitude, mapView.userLocation.coordinate.longitude);
CGPoint annPoint = [self.mapView convertCoordinate:coord toPointToView:self.mapView];
mapPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic.png"]];
mapPic.frame = CGRectMake(annPoint.x, annPoint.y, 32, 32);
[self.view addSubview:macPic];
}
使用 GCRectMake 将图像放置在用户的坐标上,但遗憾的是图像没有放置在正确的位置:
如果我移动地图,图片将始终以与用户位置完全相同的偏移量放置。我缺少什么?难道不应该直接放在用户上方吗?我猜测我首先给mapView的偏移量(-100,-100)是造成这种情况的原因(我下面有一个工具栏,因此有偏移量)。
2) 我的 iOS 5 模拟器表现得很疯狂,出于某种原因将我的位置放置在凤凰城格伦代尔(不应该在库比蒂诺吗??),并且表现得就像我正在向东移动一样;不过,我的 iPhone 4 一切正常(除了图片位置不正确)。有任何想法吗?
3)我一直在考虑使用注释,但我听说它们是静态的(而且我真的需要它们是动态的)。这是真的?
Thanks!
添加子视图时,其框架原点是相对于其父视图的框架原点。在本例中,您从地图视图中派生出原点,然后将图像添加到视图控制器的视图中。您需要将图像的原点转换为 self.view 的坐标系,如下所示:
CGPoint imageOrigin = [self.view convertPoint:annPoint fromView:self.mapView];
mapPic.frame.origin = imageOrigin;
[self.view addSubview:macPic];
注意:这是未经测试的代码,但主要是您需要在 mapView 的坐标空间(这是您从 [self.mapView ConvertCooperative:coord toPointToView:self.mapView] 获得的)到 self.view 的坐标空间之间进行转换。这个例子有点为了说明,因为更简单的方法是首先使用 self.view 的坐标空间:
CGPoint annPoint = [self.mapView convertCoordinate:coord toPointToView:self.view];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)