Move MKMapView point to pixel coordinates

柔情痞子 提交于 2019-12-06 01:04:48

EDIT:

Ok so I messed around with this a little and was able to to put something together that seems to work, hoping that I now actually understand what you're trying to achieve!

- (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];
}

Let me quickly explain what this does; Let's say you want your annotation to move to a position 20 points in from the right edge and 20 points up from the bottom edge of the map view. If you think about it, if the current annotation is at the center of the map view, then the distance to this point is the same as the distance to (20, 20). This means that we can send our annotation to this point by first centering our map view on the annotation, then animating to (20, 20).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!