如何通过注释获取mkmapview位置

时间:2015-12-29 09:50:21

标签: ios objective-c mkmapview mapkit

在我的应用程序中,我使用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;
}

请帮助我,我想显示位置,因为我将针拖到别针。

1 个答案:

答案 0 :(得分:2)

请检查此answer,这与您要寻找的答案类似,只是那个人想要协调用户放置针脚的位置。

以下是您提出的问题的same answer