2011-05-16 26 views
1

我需要幫助顯示用戶在我的MapView上的位置。我儘可能在網上找到了所有的東西,但它仍然無法正常工作。MKMapKit不顯示userLocation

我在我的AppDelegate中有一個CLLocationManager,它在我的viewController中調用locationUpdate。

(void)locationUpdate:(CLLocation *)location方法被調用每次和與NSLog().記錄靜止時location座標是正確的,沒有「藍點」我的iPhone的屏幕上。該地區不是很好。

請看看,並告訴我,如果我失去了什麼。

這是我的頭文件:

//My .h file 
#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 
#import <MapKit/MKAnnotation.h> 
#import <MapKit/MKReverseGeocoder.h> 
@interface FirstViewController : UIViewController <MKMapViewDelegate> 
{ 
    MKMapView *mapView; 
} 
-(void)locationUpdate:(CLLocation *)location; 
-(void)locationError:(NSError *)error; 
@end 

這是我的我的實現文件的一部分:

//My .m file 
#import "FirstViewController.h" 
@implementation FirstViewController 
- (void)viewDidLoad 
{ 
    mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; 
    mapView.showsUserLocation = YES; 
    mapView.mapType = MKMapTypeStandard; 
    mapView.delegate = self; 

    CLLocationCoordinate2D location; 
    MKCoordinateRegion region;// = {{0.0,0.0},{0.0,0.0}}; 
    location.latitude = -33.8771; 
    location.longitude = 18.6155; 
    MKCoordinateSpan span; 
    span.latitudeDelta = 0.01; 
    span.longitudeDelta = 0.01; 
    region.span = span; 
    region.center = location; 
    [mapView setRegion:region animated:TRUE]; 
    [mapView regionThatFits:region]; 
    [super viewDidLoad]; 
} 
-(void)locationUpdate:(CLLocation *)location 
{ 
    CLLocationCoordinate2D loc = [location coordinate]; 
    [mapView setCenterCoordinate:loc]; 
    if([mapView showsUserLocation] == NO) 
    [mapView setShowsUserLocation:YES]; 
    NSLog(@"User Loc: %f, %f", mapView.userLocation.location.coordinate.latitude, 
        mapView.userLocation.location.coordinate.longitude); 
    NSLog(@"In MapView: %@",[location description]); 
} 
@end 

謝謝您的時間! 非常感謝!

+1

你有沒有看到任何地圖?你爲什麼不在mapView上做addSubView?你在模擬器中運行嗎? – Anna 2011-05-16 16:58:57

+0

我正在看到完全縮小的世界地圖。然後手動放大到我的辦公室。看起來像「地圖」上的普通地圖 - 查看。 MapView位於TabBarController的其中一個窗格上。我在模擬器和iPhone 4上運行。 – LouwHopley 2011-05-16 19:20:08

+0

我認爲您看到的地圖是您在Interface Builder中創建的地圖,但它未連接到視圖控制器中聲明的地圖。 – Anna 2011-05-16 19:23:48

回答

3

您在Interface Builder中的地圖工具包需要檢查(查找用戶位置)!