您好,登錄后才能下訂單哦!
#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <CoreLocation/CoreLocation.h> @interface DXWViewController : UIViewController<CLLocationManagerDelegate> @property (retain, nonatomic) IBOutlet MKMapView *mapview; @property(retain,nonatomic)CLLocationManager *manager; @property(retain,nonatomic)CLLocation *location; @property (retain, nonatomic) IBOutletCollection(UILabel) NSArray *labels; @end
#import "DXWViewController.h" #import "Place.h" @interface DXWViewController () @end @implementation DXWViewController - (void)viewDidLoad { [super viewDidLoad]; self.manager = [[CLLocationManager alloc] init]; self.manager.delegate = self; //精度 self.manager.desiredAccuracy = kCLLocationAccuracyBest; [self.manager startUpdatingLocation]; self.mapview.showsUserLocation = YES; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { self.location = [locations objectAtIndex:0]; [self.labels[0] setText:[NSString stringWithFormat:@"%f\u00B0",self.location.coordinate.longitude]]; [self.labels[1] setText:[NSString stringWithFormat:@"%f\u00B0",self.location.coordinate.longitude]]; [self.labels[2] setText:[NSString stringWithFormat:@"%gm",self.location.horizontalAccuracy]]; [self.labels[3] setText:[NSString stringWithFormat:@"%gm",self.location.altitude]]; [self.labels[4] setText:[NSString stringWithFormat:@"%gm",self.location.verticalAccuracy]]; Place *place = [[Place alloc] init]; place.coordinate = self.location.coordinate; place.title = @"Title"; place.subtitle = @"subTitle"; [self.mapview addAnnotation:place]; //設(shè)置精度范圍 MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(place.coordinate, 1000, 1000); [self.mapview setRegion:region animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)dealloc { [_mapview release]; [_labels release]; [super dealloc]; } @end
#import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface Place : NSObject<MKAnnotation> @property(copy,nonatomic)NSString *title; @property(copy,nonatomic)NSString *subtitle; @property(assign,nonatomic)CLLocationCoordinate2D coordinate; @end
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。