在我的应用程序中,我使用MKmapview
我想要显示位置,因为我将引脚拖动到引脚。
如何通过别针获取位置?当我将引脚拖到引脚时,我想显示位置。
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.mapView.centerCoordinate = userLocation.coordinate;
CLLocationDistance distance = 1500;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, distance, distance);
MKCoordinateRegion adjusterRegion = [self.mapView regionThatFits:region];
[self.mapView setRegion:adjusterRegion animated:YES];
self.latitudeValue.text = [NSString stringWithFormat:@"%f",userLocation.coordinate.latitude];
self.longtitudeValue.text = [NSString stringWithFormat:@"%f",userLocation.coordinate.longitude];
custom *location = [[custom alloc] initWithTitle:@"location" subtitle:@"" location:userLocation.coordinate];
[self.mapView addAnnotation:location];
MKCoordinateRegion regions = {{0.0,0.0},{0.0,0.0}};
regions.center.latitude = 13.905726;
regions.center.longitude = 100.52142100000003;
regions.span.latitudeDelta = 0.01f;
regions.span.longitudeDelta = 0.01f;
[self.mapView setRegion:region animated:YES];
customlocation *locs = [[customlocation alloc] initWithTitle:@"test" subtitle:@"" location:regions.center];
[self.mapView addAnnotation:locs];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *reuseId = @"pin";
MKPinAnnotationView *pa = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (pa == nil)
{
pa = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
pa.draggable = YES;
pa.canShowCallout = YES;
}
else
{
pa.annotation = annotation;
}
return pa;
}
请帮助我,我想显示位置,因为我将针拖到别针。