本文介绍了iPhone SDK:将MKMapPoint转换为CGPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将MapView上的经度和纬度转换为MKMapPoint。然后,我想使用imageViews center属性将imageView移动到该点。似乎我不知何故需要将MKMapPoint转换为CGPoint以便我可以更改中心,但数字似乎已经过时了。以下是我正在使用的内容:
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;
关于如何使我的MKMapPoint成为可用于图像中心属性的值的想法?
Ideas on how to make my MKMapPoint a workable value to use for the center property of my image?
推荐答案
看起来MKMapView有一个方法可以做到这一点:
Looks like MKMapView has a method for doing this:
CGPoint newCenter = [self.map convertCoordinate:coord toPointToView:self.map];
这篇关于iPhone SDK:将MKMapPoint转换为CGPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!