-1
我是Objective-C/IOS的新手,我正在學習如何在地圖上實現用戶的當前位置。按照說明,但當我按下按鈕來查看我的當前位置,沒有任何反應。任何人都可以給我一個提示嗎?我使用的是最新版本的Xcode,我不知道,如果一個教程是一樣的...代碼:IOS/Objective-c:關於MKMapView的問題
ViewController.m:
#import "ViewController.h"
#import "Pin.h"
@interface ViewController()
@end
@implementation ViewController;
@synthesize mapview;
- (void)viewDidLoad {
[super viewDidLoad];
MKCoordinateRegion region={{0.0,0.0},{0.0,0.0}};
region.center.latitude=38.711995;
region.center.longitude=-9.144932;
region.span.longitudeDelta=0.01f;
region.span.latitudeDelta=0.01f;
[mapview setRegion:region animated:YES];
Pin*vega =[[Pin alloc] init];
[email protected]"Capela";
[email protected]"Bar";
vega.coordinate= region.center;
[mapview addAnnotation:vega];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)SetMap:(id)sender{
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview.mapType=MKMapTypeStandard;
break;
case 1:
mapview.mapType=MKMapTypeSatellite;
break;
case 2:
mapview.mapType=MKMapTypeHybrid;
break;
default:
break;
}
}
-(IBAction)GetLocation:(id)sender{
mapview.showsUserLocation=YES;
}
(IBAction)Directions:(id)sender{
NSString * [email protected]"http://maps.apple.com/maps?daddr=38.711995, -9.144932";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
@end
VieController.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController{
MKMapView * mapview;
}
@property(nonatomic,retain)IBOutlet MKMapView* mapview;
-(IBAction)SetMap:(id)sender;
-(IBAction)GetLocation:(id)sender;
-(IBAction)Directions:(id)sender;
@end
而且在連接檢查一切(按鈕)設置..
你必須檢查的位置權限 –