2017-06-01 45 views
0

我正在使用Google Maps SDK獲取當前位置。我的疑問是,如何使用使用Google Maps SDK的委託方法進行位置更新。有沒有用於獲取當前位置和位置更新的委託方法?如何使用Google Maps SDK更新位置

@implementation MyLocationViewController { 
    GMSMapView *mapView_; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868 longitude:151.2086 zoom:12]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView_.settings.compassButton = YES; 
    mapView_.settings.myLocationButton = YES; 

    // Listen to the myLocation property of GMSMapView. 
    [mapView_ addObserver:self forKeyPath:@"myLocation" 
    options:NSKeyValueObservingOptionNew context:NULL]; 

    self.view = mapView_; 

    // Ask for My Location data after the map has already been added to the UI. 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     mapView_.myLocationEnabled = YES; 
    }); 
} 
+0

您應該使用「Google地圖」在您的iOS設備上顯示位置。 要獲取當前位置並重復更新,您應該使用「CLLocationManager」。讓我知道是否需要幫助。 –

+0

@iCoderzDevelopers感謝您的回覆。你能否寄給我任何更新地點的樣本代碼。我需要一個委託方法..對於那個..我是新來的ios開發 – user3214012

回答

-1

可以使用CLLocationManager委託方法來更新,並將該位置設爲地圖。

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations; 

此委託方法將更新位置。在該方法內部,您可以將地圖視圖設置爲接收的座標。

_currentLocation = [locations lastObject]; 
CLLocationCoordinate2D target = 
    CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation(This is the current location of the user).coordinate.longitude); 
_googleMap.camera = [GMSCameraPosition cameraWithTarget:target zoom:16]; 
相關問題