相关疑难解决方法(0)

将MKMapView更新为从CLGeocoder返回的CLPlacemark

我希望能够通过允许用户在UIAlertView中键入地址或位置来更新MKMapView上显示的区域.我目前有:

        if (geocoder.geocoding)
            [geocoder cancelGeocode];

        [geocoder geocodeAddressString:[[alertView textFieldAtIndex:0] text] completionHandler:^(NSArray *placemarks, NSError *error) {
            if (!error) {
                NSLog(@"Found a location");
            } else {
                NSLog(@"Error in geocoding");
            }

            NSLog(@"Num found: %d", [placemarks count]);

            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            MKCoordinateRegion region;
            region.center.latitude = placemark.region.center.latitude;
            region.center.longitude = placemark.region.center.longitude;
            MKCoordinateSpan span;
            double radius = placemark.region.radius / 1000;

            NSLog(@"Radius is %f", radius);
            span.latitudeDelta = radius / 112.0;
            //span.longitudeDelta = ??? 

            region.span = span;

            NSLog(@"Region is %f %f %f", region.center.latitude, region.center.longitude, span.latitudeDelta);

            [mapView setRegion:region animated:YES];
        }]; …
Run Code Online (Sandbox Code Playgroud)

mkcoordinateregion mkmapview cllocation ios clgeocoder

3
推荐指数
1
解决办法
2902
查看次数