8

我已将 MapView 上的经度和纬度转换为 MKMapPoint。然后,我想使用 imageViews center 属性将 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 成为可用于图像中心属性的可行值的想法?

4

1 回答 1

10

看起来 MKMapView 有这样做的方法:

CGPoint newCenter = [self.map convertCoordinate:coord toPointToView:self.map];
于 2010-11-09T00:54:29.827 回答