iPhone SDK: Convert MKMapPoint to CGPoint
Asked Answered
J

1

8

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?

Jaimiejain answered 9/11, 2010 at 0:12 Comment(0)
J
10

Looks like MKMapView has a method for doing this:

CGPoint newCenter = [self.map convertCoordinate:coord toPointToView:self.map];
Jaimiejain answered 9/11, 2010 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.