地图的使用

来源:互联网 发布:上国际学校的利弊知乎 编辑:程序博客网 时间:2024/04/28 07:15
<pre name="code" class="objc">

#import "ViewController.h"#import <MapKit/MapKit.h>@interface ViewController ()<MKMapViewDelegate>@property(nonatomic, retain)MKMapView *map;@property(nonatomic, retain)CLGeocoder *geocoder;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.map = [[MKMapView alloc]initWithFrame:self.view.frame]; self.map.delegate = self; self.map.showsUserLocation = YES; [self.view addSubview:self.map]; self.geocoder = [[CLGeocoder alloc]init]; [self.geocoder geocodeAddressString:@"黑石礁汽车站,大连市,辽宁省" completionHandler:^(NSArray *placemarks, NSError *error) { MKPlacemark *placemark = [[MKPlacemark alloc]initWithPlacemark:[placemarks lastObject]]; [self.map addAnnotation:placemark]; [self.map setRegion:MKCoordinateRegionMake(self.map.centerCoordinate, MKCoordinateSpanMake(0.01f, 0.0f)) animated:YES]; }];}-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{ mapView.centerCoordinate = userLocation.coordinate;//中心点的坐标为用户坐标}

0 0