简体   繁体   中英

Unable to assign a CLLocationCoordinate2D to another CLLocationCoordinate2D

I am getting the following error:

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

At the following line below:

 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]; 


        }
    }];


}

What am I doing wrong?

The error tells you all. You are assigning a CLLocationCoordinate2D value (see NO POINTER) to a pointer ( CLLocationCoordinate2D * ) You can use & to get the adress of a variable. Also known as pointer . So you can either do locationMapViewController.centerOfMap = &coordinate; or set the latitude and longitude values directly.

Cheers,

George

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM