将MKMapView点移动到像素坐标

3

我有一个问题。我正在使用自定义视图作为我的地图视图的标注附件。我在将标注移动到该视图的右下角方面遇到了一些问题。我目前正在尝试获取所选注释的CGPoint坐标,但除此之外我一无所获。任何帮助都将不胜感激。

我当前正在使用的代码(我知道它是不正确的)是:

   CGPoint bottomLeftPoint = CGPointMake(xOffset,[self.internalAnnotationCallout view].frame.size.height);
CLLocationCoordinate2D bottomLeftCoord = [self.branchLocation convertPoint:bottomLeftPoint toCoordinateFromView:self.branchLocation];
MKCoordinateSpan span = {latitudeDelta: kMapMultiLatDelta, longitudeDelta: kMapMultiLatDelta};
  MKCoordinateRegion region = {bottomLeftCoord, span};
 [self.branchLocation setRegion:region animated:YES];
//[self.branchLocation setCenterCoordinate:newCenterCoordinate animated:YES];

编辑:Callout视图具有静态坐标。我只想让选定的注释无论在地图上的位置如何,都移到视图的右下角。 - John S
1个回答

7

编辑:

好的,我稍微做了些尝试,并成功地组合了一些东西,看起来它似乎可行,希望现在我真正理解你想要达到的目标!

- (void)shiftToCorner{
    //ignore "Annotation", this is just my own custom MKAnnotation subclass
    Annotation *currentAnnotation = [[mapView selectedAnnotations] objectAtIndex:0];
    [mapView setCenterCoordinate:currentAnnotation.coordinate];

    CGPoint fakecenter = CGPointMake(20, 20);
    CLLocationCoordinate2D coordinate = [mapView convertPoint:fakecenter toCoordinateFromView:mapView];
    [mapView setCenterCoordinate:coordinate animated:YES];
}

让我简单地解释一下这个操作的作用;假设您想要将注释移到地图视图右侧边缘内20个点和底部边缘内20个点的位置。如果您考虑一下,如果当前的注释位于地图视图的中心,则到达此点的距离与到达(20,20)的距离相同。这意味着我们可以通过首先将地图视图居中于注释,然后动画移动到(20,20)来将我们的注释发送到该点。

哎呀,这在评论中很难阅读,你能把它添加到你的问题中吗? - mjisrawi
我该如何将所选注释的旧坐标转换为新预设坐标? - John S
你是否正在尝试将注释移动到新的地图坐标? - mjisrawi
是的,我正在尝试移动地图,使选定的注释与我的视图底部角匹配,即假设底部角是CGPoint(160,300)。我的问题是让地图滚动到该点以显示选定的注释。 - John S
移动标注有两种方法:一种是在地图视图代理中实现拖动支持(用户仍然需要实际拖动它到新位置),另一种是通过编程删除标注,更改其坐标并将其重新添加到地图视图中。 - mjisrawi
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接