ITeye博客

MKMapView 显示当前位置

修博龙泉 · 2012-12-03 17:14 · ios开发学习相关 · 移动开发 · Markdown


//显示地图
    MKMapView *mapView = [[mkmapview alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    mapView.showsUserLocation = YES;
    [self.view addsubview:mapview];
    
    //显示当前用户经纬度,自动缩放到1000米
    CLLocationManager *locationManager = [[cllocationmanager alloc] init];//创建位置管理器
    locationManager.delegate=self;//设置代理
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
    locationManager.distanceFilter=10.0f;//设置距离筛选器
    [locationmanager startupdatinglocation];//启动位置管理器
    MKCoordinateSpan theSpan;
    
    //地图的范围 越小越精确
    theSpan.latitudeDelta=0.05;
    theSpan.longitudeDelta=0.05;
    MKCoordinateRegion theRegion;
    theRegion.center=[[locationmanager location] coordinate];
    theRegion.span=theSpan;
    [mapview setregion:theregion];
    [locationmanager release];
    
    [mapview release];


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。