jeudi 13 août 2015

ios Google Map - how to get my device location without zooming to the camera

I am working on the button to get my location regularly. When it comes to the implementation, the device will let Google Map camera being center of the map regularly even without using GMSCameraUpdate to focus. Would you please tell me what to enhance so that we can regularly get the updated device location without camera zooming?

The below is my working on triggering the zooming after onClick

 if(self.myMapView.myLocation !=nil){
        [self.locationManager stopUpdatingLocation];
        [CATransaction begin];
        [CATransaction setAnimationDuration:0.2];
        GMSCameraUpdate *move = [GMSCameraUpdate setTarget:self.myMapView.myLocation.coordinate  zoom:self.myMapView.camera.zoom];
        [self.myMapView animateWithCameraUpdate:move];
        [CATransaction commit];
    }

Delegate after getting location

- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations{
    CLLocation *location = [locations lastObject];


    if(location==nil){
        location = self.myMapView.myLocation;
    }

    myDeviceLocation = location;

    NSLog(@"adasdads zoom ");
    if (markera == nil) {
        markera = [[GMSMarker alloc] init] ;
        markera.position   = CLLocationCoordinate2DMake(22.2855200, 114.1576900);
        markera.groundAnchor = CGPointMake(0.5f, 0.97f); // Taking into account walker's shadow

        markera.map = self.myMapView;


    }else {
        [CATransaction begin];
        [CATransaction setAnimationDuration:2.0];
        markera.position = location.coordinate;
        markera.icon = nil;
        [CATransaction commit];

    }

    GMSCameraUpdate *move = [GMSCameraUpdate setTarget:location.coordinate zoom:17];
    [self.myMapView animateWithCameraUpdate:move];
}



-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)statusX {

    NSLog(@"status  : %d" , statusX);
    if (status == kCLAuthorizationStatusDenied) {
        //location denied, handle accordingly
        NSLog(@"denied ");

    }
else if (statusX == kCLAuthorizationStatusAuthorized) {
    //hooray! begin startTracking
    NSLog(@"proceed ");
    dispatch_async(dispatch_get_main_queue(), ^{
        self.myMapView.myLocationEnabled = YES;
    });



}else   if (statusX == kCLAuthorizationStatusAuthorizedAlways || statusX == kCLAuthorizationStatusAuthorizedWhenInUse) {
    self.myMapView.myLocationEnabled = YES;

    NSLog(@"gogogo ");
    dispatch_async(dispatch_get_main_queue(), ^{
      //  self.myMapView.myLocationEnabled = YES;
    });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire