2015-08-14 23 views
0

我正在按钮来定期获取我的位置。当涉及到实施时,即使没有使用GMSCameraUpdate进行关注,该设备也会定期将Google Map相机作为地图的中心。您能否告诉我需要增强哪些功能,以便我们可以定期获取更新的设备位置而无需缩放摄像头?ios谷歌地图 - 如何让我的设备位置不缩放到相机

下面是我在获取位置

- (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; 
    }); 
+0

删除'didUpdateLocations'变更地图视摄像头的代码?现在删除了 – Paulw11

+0

,但是当调用startUpdateLocation时,仍然是相机对焦 –

回答

1

你可以试试这个

didUpdateLocations委托中删除此代码后

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]; 
    } 

代表触发变焦的onClick后的工作:

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

将它移到一个可以稍后调用的新函数。

didUpdateLocations设置您的新用户位置,然后致电[locationManager stopUpdatingLocation],然后调用您的新自定义功能来设置相机。

在新的自定义功能,更改:

[self.myMapView animateWithCameraUpdate:move];

要:

CLLocationCoordinate2D target = myLocation; //2d coord 
self.myMapView.camera = [GMSCameraPosition cameraWithTarget:target zoom:17];