位置坐标给出错误的CGPoint值?

时间:2016-04-26 08:40:47

标签: ios objective-c cllocationmanager cllocationcoordinate2d

我想获取当前位置CGPoint值。我可以获取当前位置值,从中我尝试得到它但是它没有给出正确的原点

-(void)addCircleToUserLocation{
    CLLocationCoordinate2D center = CLLocationCoordinate2DMake( _locationManager.location.coordinate.latitude, _locationManager.location.coordinate.longitude);
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 50, 50);
    CGRect rect = [mapView  convertRegion:region toRectToView:mapView];
//    CGRect rect;
//    CGPoint point=[mapView convertCoordinate:center toPointToView:mapView];
//    rect.origin.x=point.x;
//    rect.origin.y=point.y;
//    rect.size.width=100;
//    rect.size.height=100;
   NSLog(@"%f,%f",rect.origin.x,rect.origin.y);

}

控制台: 的x 700.736190,γ-329.035629

这里我通过添加此行显示用户位置

mapView.showsUserLocation = YES;
        mapView.userTrackingMode = MKUserTrackingModeFollow;

MAP

上添加注释
#define ARC4RANDOM_MAX      0x10000000000
- (void )createAnnotations:(NSMutableArray *)arrayList
{
    PinAnnotation*  pinAnnotation;
    [mapView removeAnnotations:mapView.annotations];
    CLLocationCoordinate2D coordinates;
    for (int i=0; i<=[arrayList count]; i++) {
        CLLocationCoordinate2D cor;
        double latDelta = ((double)arc4random() / ARC4RANDOM_MAX);
        double lonDelta = ((double)arc4random() / ARC4RANDOM_MAX);
        cor.latitude=[latitude doubleValue]+latDelta;
        cor.longitude=[longitude doubleValue]+lonDelta;
        pinAnnotation = [[PinAnnotation alloc] init];
        pinAnnotation.tag=i;
        pinAnnotation.coordinate = cor;
        if (i==[arrayList count]-1) {
            coordinates=cor;
        }
        [mapView addAnnotation:pinAnnotation];
        ;
    }
    //[self setRoot:&coordinates];

    //[self zoomMapViewToFitAnnotations:mapView animated:YES];
}

我在当前位置随机添加引脚。我想获得当前位置值的CGPoint。

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

CLLocationCoordinate2D center = CLLocationCoordinate2DMake( _locationManager.location.coordinate.latitude, _locationManager.location.coordinate.longitude);

CGPoint Centerpoint = [mapView convertCoordinate:center toPointToView: mapView];