Map

Map.zip (466.6 KB)



关键代码:

初始化:

region.center =CLLocationCoordinate2DMake(39.541997,116.232934);

region.span =MKCoordinateSpanMake(50.0,50.0);   


locationManager = [[CLLocationManageralloc] init];

locationManager.delegate =self;

locationManager.desiredAccuracy =kCLLocationAccuracyBest;

locationManager.distanceFilter =kCLHeadingFilterNone;

[locationManagerstartUpdatingLocation];


mapView = [[MKMapViewalloc] init];

[mapView.userLocationsetTitle:@"我的位置"];

mapView.delegate =self;

mapView.showsUserLocation =YES;

[mapViewsetRegion:regionanimated:YES];



通过代理更新坐标:


- (void)locationManager:(CLLocationManager *)manager

didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation {

    

    NSLog(@"当前坐标:%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);

   region.center = [[locationManagerlocation] coordinate];

    [mapViewsetRegion:regionanimated:YES];

    [locationManagerstopUpdatingLocation];

    

}





















你可能感兴趣的:(Map)