何时使用CLLocationManager或Google Maps myLocation

时间:2014-05-06 17:06:16

标签: objective-c google-maps-sdk-ios

我正在使用Google Maps SDK,并试图找出如何将我的地图置于当前位置的中心位置。

- (void)viewDidLoad {
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.7127
                                                        longitude:-74.0059
                                                             zoom:12];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    mapView_.settings.myLocationButton = YES;
    self.view = mapView_;
    mapView_.delegate = self;

}

我正在尝试从调试>设置当前位置设置当前位置,但所有位置都显示为灰色。我认为位置可能在某个地方是硬编码的,因为当我点击当前位置箭头时它会把我带到其他地方。如何选择当前位置,将地图置于该位置的中心位置并查看当前位置的蓝点?

1 个答案:

答案 0 :(得分:0)

使用位置管理器

CLLocationManager* locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100m
[locationManager startUpdatingLocation];

创建gmap视图

GMSCameraPosition* camera;
GMSMapView* mapView;
 camera = [GMSCameraPosition cameraWithLatitude: locationManager.location.coordinate.latitude
                                              longitude: locationManager.location.coordinate.longitude
                                                   zoom:12];
mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view addSubview:mapView];