iPhone SDK:将MKMapPoint转换为CGPoint

8

我已将地图视图上的经度和纬度转换为MKMapPoint。然后,我想使用imageView的中心属性将imageView移动到该点。但是,似乎我需要将MKMapPoint转换为CGPoint,以便我可以更改中心位置,但数字似乎完全不对。以下是我正在使用的代码:

// Convert to MKMapPoint
    CLLocationCoordinate2D coord;
    coord.latitude = [loc.latitude doubleValue];
    coord.longitude = [loc.longitude doubleValue];
    MKMapPoint point = MKMapPointForCoordinate(coord);

    // Move our image
    CGFloat newXPos = point.x;
    CGFloat newYPos = point.y;
    CGPoint newCenter = {newXPos, newYPos};
    self.movingMarker.center = newCenter;

    //self.movingMarker.frame.origin.x = point.x;
    //self.movingMarker.frame.origin.y = point.y;

如何使我的MKMapPoint成为可用于图像中心属性的有效值?

1个回答

10

看起来MKMapView有一个可以做到这个的方法:

CGPoint newCenter = [self.map convertCoordinate:coord toPointToView:self.map];

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