如何在iPhone中的谷歌地图sdk中获取当前位置

use*_*201 4 iphone google-maps google-maps-sdk-ios

我想将相机设置在当前位置,并将缩放级别设置为10.所以我编写了这样的代码,对于当前位置,我从这篇文章中得到提示.

如何在IOS 6的Google Map API中使用委托

这是我的代码

mapView_=[[GMSMapView alloc]initWithFrame:CGRectZero];

CLLocationCoordinate2D currentPosition = mapView_.myLocation.coordinate;

 GMSCameraPosition* camera =
[GMSCameraPosition cameraWithTarget: currentPosition zoom: 10];
 mapView_.camera = camera;
 mapView_.delegate=self;

  mapView_.mapType = kGMSTypeSatellite;
  mapView_.myLocationEnabled = YES;

  self.view = mapView_;
  mapView_.settings.myLocationButton = YES;
Run Code Online (Sandbox Code Playgroud)

但设备中的坐标为0.00.

请问任何可以帮助解决这个问题?

Stu*_*ner 8

试试这个:

@property (nonatomic, retain) IBOutlet GMSMapView *googleMapView;
@property (nonatomic, retain) CLLocationManager *locationManager;

- (void)showCurrentLocation {
    _googleMapView.myLocationEnabled = YES;
    [self.locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
            GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude 
                                                                    longitude:newLocation.coordinate.longitude 
                                                                         zoom:17.0];
            [_googleMapView animateToCameraPosition:camera];
        //...
}
Run Code Online (Sandbox Code Playgroud)