iPhone SDK:将 MKMapPoint 转换为 CGPoint

发布于 2024-10-01 14:33:57 字数 709 浏览 0 评论 0原文

我已将 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 成为可用于图像中心属性的可行值的想法?

I have converted a longitude and latitude on my MapView to a MKMapPoint. I then want to move an imageView to that point using the imageViews center property. It seems that I somehow need to convert the MKMapPoint to a CGPoint so that I can change the center, but the numbers seem to be way off. Here is what I am using:

// 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;

Ideas on how to make my MKMapPoint a workable value to use for the center property of my image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2024-10-08 14:33:57

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

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

Looks like MKMapView has a method for doing this:

CGPoint newCenter = [self.map convertCoordinate:coord toPointToView:self.map];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文