1

当用户单击按钮时,我的地图当前正在工作。

当用户单击按钮时,如何放大地图并可能在地图中显示动画。

这是hte主要文件和头文件。另外,如何显示我的当前位置?

在此先感谢主文件

@synthesize map;


//Add Map overlay

-(MKOverlayView*)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay{



    MKCircleView* circleView =[[MKCircleView alloc] initWithOverlay:overlay];

    circleView.strokeColor = [UIColor blueColor];

    circleView.fillColor = [UIColor redColor];

    return circleView;



}


-(IBAction)onLocationButtonTop:(id)sender {





    UIBarButtonItem* b = (UIBarButtonItem*) sender;

    int tag = b.tag;



    float latitude = 40.0;

    float longitude  = -75.0;



    if(tag == 1){

        latitude = 57.15;longitude  = -2.15;

    }

    else if(tag == 2){

        latitude = 39.91;longitude  = 116.41;

    }

    else{

        latitude = -1.46;longitude  = -48.48;

    }



    CLLocationCoordinate2D x;

    x.latitude = latitude;

    x.longitude = longitude;









    MKCoordinateSpan z;

    z.latitudeDelta = 0.25;

    z.longitudeDelta = 0.25;



    MKCoordinateRegion y;

    y.center = x;

    y.span = z;



    map.region = y;

    [map addOverlay:[MKCircle circleWithCenterCoordinate:x

                                                 radius:1000]];



}

h 文件

#import <UIKit/UIKit.h>

#import <MapKit/MapKit.h>


@interface MapExampleK2ViewController : UIViewController <MKMapViewDelegate>



@property (strong,nonatomic) IBOutlet MKMapView* map;


-(IBAction)onLocationButtonTop:(id)sender;



@end
4

1 回答 1

1

对于您问题的第二部分,您可以使用 CLLocationManager 获取当前位置,然后在位置更新时使用 setRegion。您可以参考发布在http://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010726上的区域代码。

下面是该代码中的函数,它将地图上的焦点设置为您当前的位置。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"didUpdateToLocation %@ from %@", newLocation, oldLocation);
    
        if (oldLocation == nil) {
        // Zoom to the current user location.
        MKCoordinateRegion userLocation = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 1500.0, 1500.0);
        [regionsMapView setRegion:userLocation animated:YES];
    }
}
于 2012-07-15T13:34:17.940 回答