我只是看着mapKit,並決定做一個快速按鈕來顯示我的當前位置,但是當我按下按鈕時,我的緯度/經度始終顯示爲[0.000000] [0.000000]。userLocation:緯度/經度返回零?
mapView被加載,因爲我可以在按下按鈕之前在模擬器上看到地圖。以前我通過使用coreLocation.framework並使用CLLocationManager並以這種方式詢問設備位置來完成此操作。我只是好奇,爲什麼這種方式不能正常工作,我會更好地通過CLLocationManager做到這一點?
-(IBAction)findMePressed {
MKUserLocation *myLocation = [myMapView userLocation];
CLLocationCoordinate2D coord = [[myLocation location] coordinate];
[myMapView setCenterCoordinate:coord animated:YES];
NSLog(@"findMePressed ...[%f][%f]", coord.latitude, coord.longitude);
}
編輯:添加...
-(IBAction)findMePressed {
MKUserLocation *myLocation = [myMapView userLocation];
CLLocationCoordinate2D coord = [[myLocation location] coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 350, 350);
[myMapView setRegion:region animated:YES];
}
-(void)viewDidLoad {
[super viewDidLoad];
[myMapView setShowsUserLocation:YES];
}
加里。
嗨院長,userLocationVisible爲[0],所以我想這就是問題所在。 myMapView連接到IB,因此它正確指向我的iVar。 – fuzzygoat 2010-07-05 13:31:31
我的地圖顯示庫比蒂諾的方式就在顯示屏的左側。設置showUserLocation並創建一個區域做了我期待的事,非常感謝。 – fuzzygoat 2010-07-05 13:55:13