2014-10-19 78 views
1

我試圖在我的應用程序中實現當前位置。請參閱我的代碼如下viewDidLoad當前位置的藍點不顯示使用谷歌地圖的iOS

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self hideTabBar:self.tabBarController]; 

    // Create a GMSCameraPosition that tells the map to display the 
    // coordinate -33.86,151.20 at zoom level 6. 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView_.myLocationEnabled = YES; 
    mapView_.settings.compassButton = YES; 
    mapView_.settings.myLocationButton = YES; 
    mapView_.accessibilityElementsHidden = NO; 
    self.view = mapView_; 

    // Creates a marker in the center of the map. 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.title = @"Sydney"; 
    marker.snippet = @"Australia"; 
    marker.map = mapView_; 
} 

我可以看到在iPhone模擬器(iPhone 4S)設置爲悉尼標記的地圖,但在任何地方看到任何藍色的圓點。當前位置可能正在工作,但UI元素已隱藏?

感謝您的任何幫助/建議!

+0

您需要獲得獲取用戶位置的權限,甚至可以在MapView上顯示它。 – Lefteris 2014-10-19 00:28:59

+0

對不起,我對iOS很新。我如何申請許可?這是模擬器設置還是以編程方式完成? – BlueBucket7 2014-10-19 00:34:20

+0

看看CLLocation類的參考 – Lefteris 2014-10-19 00:37:59

回答

1

在我的應用程序中,我需要實現CLLocationManager並在自定義目標屬性中設置NSLocationWhenInUseUsageDescription

希望這會有所幫助。

0

模擬器,您需要設置自定義位置類似以下內容:

調試>位置>自定義位置...然後輸入你想要的位置的緯度和經度模擬。

注:如果這個方法不奏效,那麼就選擇高速公路驅動,而不是自定義位置。一旦您點擊高速公路驅動器,然後執行上述步驟。

相關問題