2017-06-01 23 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]; 
相关问题