2015-04-05 57 views
0

我有一个图像,我想要在用户位置的右侧,我该如何去做呢?有没有办法获得用户位置的x和y坐标,然后获取图像的x和y以确保其始终位于右侧?找到用户位置的x和y坐标

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{ 

    MKCoordinateRegion region; 
    region.center = worldView.userLocation.coordinate; 
    MKCoordinateSpan span; 
    span.latitudeDelta = 5; 
    span.longitudeDelta = 5; 
    region.span = span; 
    [worldView setRegion:region animated:YES]; 

    UIImage *commentBox = [UIImage imageNamed:@"comment-box"]; 
    UIImageView *commentBoxImageView = [[UIImageView alloc] initWithImage:commentBox]; 
    [self.view addSubview:commentBoxImageView]; 

} 

回答

1

最简单的解决方案是使该图像成为注释视图。这是属于地图视图的东西 - 地图将绘制注记视图,并在地图滚动或区域更改时将其保留在其坐标处。现在你所要做的就是继续观察用户的坐标并确保注释位于该坐标的东边。