我在使用 MKMapView 时遇到了一些问题!我是地图新手!我正在尝试做的事情:
Mapview 在用户的当前位置和所选客户的地址上加载并放置一个地标。此代码在所选客户的地址上放置一个地标,但我似乎无法让它在用户的当前位置放置一个!
任何想法为什么?
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:postcodeForMap
completionHandler:^(NSArray* placemarks, NSError* error){
NSLog(@"Co-ordinate geocode is %@", [placemarks objectAtIndex:0]);
for (CLPlacemark* aPlacemark in placemarks)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKPlacemark *mPlacemark = [[MKPlacemark alloc] initWithCoordinate:mapView.userLocation.location.coordinate addressDictionary:nil];
MKCoordinateRegion region = mapView.region;
region.center = placemark.region.center;
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;
[mapView setRegion:region animated:YES];
[mapView addAnnotation:placemark];
[mapView addAnnotation:mPlacemark];
}
}
];