Google Maps iOS当前位置默认值

时间:2018-05-22 16:28:30

标签: ios swift xcode google-maps

有谁知道如何将默认摄像头位置设置为用户当前位置? 感谢。

let camera = GMSCameraPosition.camera(withLatitude: 56.8, longitude: 14.8, zoom: 13)
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    mapView.isMyLocationEnabled = true

1 个答案:

答案 0 :(得分:0)

请尝试这些代码,它会帮助您

 locationManager = [[CLLocationManager alloc] init];
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    [locationManager requestWhenInUseAuthorization];
    [locationManager requestAlwaysAuthorization];
    [locationManager startUpdatingLocation];
    latitude = locationManager.location.coordinate.latitude;
    longitude = locationManager.location.coordinate.longitude;
    self.googleMapView.delegate = self;

    GMSCameraPosition *sydney = [GMSCameraPosition cameraWithLatitude:latitude
                                                            longitude:longitude
                                                                 zoom:10];

    [_googleMapView animateToLocation:CLLocationCoordinate2DMake(longitude, longitude)];
    [self.googleMapView setMyLocationEnabled:YES];
    [_googleMapView setCamera:sydney];