无法将CLLocationCoordinate2D分配给另一个CLLocationCoordinate2D

时间:2012-07-05 22:42:51

标签: ios mkmapview cllocationmanager

我收到以下错误:

Assigning to 'CLLocationCoordinate2D *' from incompatible type 'CLLocationCoordinate2D'; take the address with &

在以下行中:

 locationMapViewController.centerOfMap = coordinate;



- (IBAction) btnLocateAddress
{

    if (!self.geocoder) {
        self.geocoder = [[CLGeocoder alloc] init];
    }


    [self.geocoder geocodeAddressString:self.address.text completionHandler:^(NSArray *placemarks, NSError *error) {
        if ([placemarks count] > 0) {
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            CLLocation *location = placemark.location;
            CLLocationCoordinate2D coordinate = location.coordinate;

            self.address.text = [NSString stringWithFormat:@"%f, %f", coordinate.latitude, coordinate.longitude];

            if ([placemark.areasOfInterest count] > 0) {
                NSString *areaOfInterest = [placemark.areasOfInterest objectAtIndex:0];
                 NSLog(@"Area of Interest: %@",areaOfInterest);
            }



        //lets push the new map screen
            LocationMapViewController *locationMapViewController = [[LocationMapViewController alloc] initWithNibName:@"LocationMapViewController_iPhone" bundle:nil];
            locationMapViewController.title=@"Your Property Listing";
            locationMapViewController.centerOfMap = coordinate;
            [self.navigationController pushViewController:locationMapViewController animated:YES]; 


        }
    }];


}

我做错了什么?

1 个答案:

答案 0 :(得分:4)

错误告诉你所有人。您正在为指针(CLLocationCoordinate2D)分配CLLocationCoordinate2D *值(请参阅NO POINTER)您可以使用&获取变量的地址。也称为pointer。因此,您可以locationMapViewController.centerOfMap = &coordinate;或直接设置latitudelongitude值。

干杯,

乔治