使用地图显示我的位置

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>

@interface mylocation : UIViewController<CLLocationManagerDelegate,MKMapViewDelegate>
@property (retain, nonatomic) IBOutlet MKMapView *m_map;
- (IBAction)return:(id)sender;

@end


http://www.zdoz.net


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.m_map.showsUserLocation=YES;
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器
    locationManager.delegate=self;//设置代理
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
    locationManager.distanceFilter=1000.0f;//设置距离筛选器
    [locationManager startUpdatingLocation];//启动位置管理器
    MKCoordinateSpan theSpan;
    //地图的范围 越小越精确
    theSpan.latitudeDelta=0.05;
    theSpan.longitudeDelta=0.05;
    MKCoordinateRegion theRegion;
    theRegion.center=[[locationManager location] coordinate];
    theRegion.span=theSpan;
    [self.m_map setRegion:theRegion];
    [locationManager release];
}


设置标注

- (IBAction)FindUs:(id)sender {
    self.UsMap.hidden = NO;
    CLLocationCoordinate2D coord;
    coord.latitude = 34.7993;
    coord.longitude = 113.6939;
    POI *poi = [[POI alloc]initWithCoords:coord];
   [UsMap addAnnotation:poi]; 
    
    MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };
    theRegion.center=coord;
    [UsMap setZoomEnabled:YES];
    [UsMap setScrollEnabled:YES];
    theRegion.span.longitudeDelta = 0.01f;
    theRegion.span.latitudeDelta = 0.01f;
    [UsMap setRegion:theRegion animated:YES];
}


@interface POI : NSObject <MKAnnotation> {   
    
    CLLocationCoordinate2D coordinate;   
    NSString *subtitle;   
    NSString *title;   
}   

@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;   
@property (nonatomic,retain) NSString *subtitle;   
@property (nonatomic,retain) NSString *title;   

-(id) initWithCoords:(CLLocationCoordinate2D) coords;   

@end 



@implementation POI   

@synthesize coordinate,subtitle,title;   

- (id) initWithCoords:(CLLocationCoordinate2D) coords{   
    
    self = [super init];   
    
    if (self != nil) {   
        
        coordinate = coords;    
        
    }   
    
    return self;   
    
}   

- (void) dealloc   

{   
    [title release];   
    [subtitle release];   
    [super dealloc];   
}   

@end  

 /获取位置信息
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray* placemarks,NSError *error)
    {
        if (placemarks.count >0   )
        {
            CLPlacemark * plmark = [placemarks objectAtIndex:0];
            
            NSString * country = plmark.country;
            NSString * city    = plmark.locality;
            
            
            NSLog(@"%@-%@-%@",country,city,plmark.name);
            self.m_locationName.text =plmark.name;
        }
        
        NSLog(@"%@",placemarks);
        
    }];
    
    //[geocoder release];


转载于:https://www.cnblogs.com/zzili/archive/2012/12/29/6663196.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值