小编Ken*_* L.的帖子

iOS - MKMapView - 可拖动注释

我准备好了注释,但试着弄清楚如何使用我的代码使其可拖动:

-(IBAction) updateLocation:(id)sender{

    MKCoordinateRegion newRegion;

    newRegion.center.latitude = mapView.userLocation.location.coordinate.latitude;
    newRegion.center.longitude = mapView.userLocation.location.coordinate.longitude;

    newRegion.span.latitudeDelta = 0.0004f;
    newRegion.span.longitudeDelta = 0.0004f;

    [mapView setRegion: newRegion animated: YES];


    CLLocationCoordinate2D coordinate;
    coordinate.latitude = mapView.userLocation.location.coordinate.latitude;
    coordinate.longitude = mapView.userLocation.location.coordinate.longitude;

    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];

    [annotation setCoordinate: coordinate];
    [annotation setTitle: @"Your Car is parked here"];
    [annotation setSubtitle: @"Come here for pepsi"];


    [mapView addAnnotation: annotation];
    [mapView setZoomEnabled: YES];
    [mapView setScrollEnabled: YES];
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

xcode annotations draggable mkmapview ios

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

annotations ×1

draggable ×1

ios ×1

mkmapview ×1

xcode ×1