【发布时间】:2015-11-07 04:20:03
【问题描述】:
我正在制作按钮以定期获取我的位置。在实现方面,即使不使用 GMSCameraUpdate 对焦,该设备也会让谷歌地图相机定期成为地图的中心。您能告诉我要增强什么,以便我们可以定期获取更新的设备位置,而无需缩放相机吗?
以下是我在 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];
}
获取位置后委托
- (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;
});
【问题讨论】:
-
从
didUpdateLocations中删除更改地图视图相机的代码? -
现已移除,但在调用 startUpdateLocation 时,相机仍对焦
标签: ios google-maps cllocationmanager