【发布时间】:2014-02-01 06:39:33
【问题描述】:
现在我在模拟器中找到了我当前的位置
当按下按钮时显示我的当前位置 但我的应用位于其他位置
.h
#import <MapKit/MapKit.h>
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
@property (nonatomic,retain)MKMapView *mapView;
- (IBAction)myview:(id)sender;
@property (strong, nonatomic) IBOutlet CLLocationManager *locationManger;
@end
.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)myview:(id)sender {
_locationManger =[[CLLocationManager alloc]init];
_locationManger.distanceFilter=kCLDistanceFilterNone;
_locationManger.desiredAccuracy=kCLLocationAccuracyHundredMeters;
[_locationManger startUpdatingLocation];
[_mapView setMapType:MKMapTypeStandard];
[_mapView setZoomEnabled:YES];
[_mapView setScrollEnabled:YES];
MKCoordinateRegion region={ {0.0,0.0 },{0.0,0.0}};
region.center.latitude=_locationManger.location.coordinate.latitude;
region.center.longitude=_locationManger.location.coordinate.longitude;
region.span.longitudeDelta=0.007f;
region.span.latitudeDelta=0.007f;
[_mapView setRegion:region animated:YES];
[_mapView setDelegate:sender];
}
@end
我想当按钮按下时我的当前位置显示在地图中
【问题讨论】:
-
"如何在 Xcode 中找到当前位置" - 从你的电脑上站起来,透过窗户向外看。这就是外面的真实世界。也许你可以找到你的房子/公寓的车牌。 (哦等等。你的意思是用户的位置?嗯,那不是“在 Xcode 中”。那是“在你的 iOS 应用程序中”。你是使用 Xcode 还是其他 IDE 完全无关紧要。这是关于程序/代码的问题,与 IDE 无关。)
标签: ios objective-c