iOS Mapkit从叠加视图获取点

时间:2015-05-28 22:14:19

标签: ios objective-c location mapkit latitude-longitude

我正在实施一个位置选择视图,我希望该引脚在地图上保持居中,这样当用户向左/向右平移地图时,引脚保持居中。为此,我在地图中心为引脚添加了子视图UIImageView。

当用户选择位置时,我试图通过以下两种方法之一检索坐标:

CLLocationCoordinate2D coord = [self.mapView convertPoint:self.pinImageView.center toCoordinateFromView:self.pinImageView];

MKCoordinateRegion myRegion = [self.mapView convertRect:self.pinImageView.frame  toRegionFromView:self.mapView];

这很有效,除了我注意到当用户将地图缩放到不同级别时,只有在垂直/纬度轴重新使用这些点时,我才会有不同大小的差异

在ViewWillAppear上,我尝试使用点重新定位地图并将其转换为区域或传递区域本身。

- (void)viewWillAppear:(BOOL)animated {

if([self.priorLatitude length] >0)
    {

        self.mapView.showsUserLocation = YES;
        CLLocationCoordinate2D priorCoordinate;
        float priorLatitudeFloat = [self.priorLatitude floatValue];
        float priorLongitudeFloat = [self.priorLongitude floatValue];

        priorCoordinate.latitude = priorLatitudeFloat;
        priorCoordinate.longitude = priorLongitudeFloat;

        //MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(priorCoordinate, 800, 800);
        //[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];

        [self.mapView setRegion:self.myRegion animated:YES];


    }

}

这里的例子是重复setLocation的日志,而不是完全移动地图和y轴的变化。

Printing description of self->_myRegion:
(MKCoordinateRegion) _myRegion = {
  center = (latitude = 43.76**9625**114267697, longitude = -79.261707572949575)
  span = (latitudeDelta = 0.00011621367119118986, longitudeDelta = 0.00017166140757751691)
}

(MKCoordinateRegion) _myRegion = {
  center = (latitude = 43.76**9454**667211292, longitude = -79.261707572949547)
  span = (latitudeDelta = 0.000116214002375159, longitudeDelta = 0.00017166140757751691)
}

0 个答案:

没有答案