chi*_*hah 16 objective-c google-maps-markers cllocationmanager ios gmsmapview
我要求在我当前的位置显示一个视图.如果设备旋转或位置将改变它将旋转.我研究很多,但得到所有代码,在某些位置有固定位置或角度但我没有固定位置.任何人都可以朝正确的方向开车.
我还使用了GMSMarker的旋转属性,但它不起作用.
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
if (newHeading.headingAccuracy < 0){
NSLog(@"heading accuracy < 0");
return;
}
// Convert Degree to Radian and move the needle
float oldRad = (- manager.heading.trueHeading) * M_PI / 180.0f;
float newRad = (- newHeading.trueHeading) * M_PI / 180.0f;
// Compass animation
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
theAnimation.toValue = [NSNumber numberWithFloat:newRad];
theAnimation.duration = 0.5f;
[source.layer addAnimation:theAnimation forKey:@"animateMyRotation"];
// source.transform = CGAffineTransformMakeRotation(newRad)
// GMSMarker *source = [googleMap selectedMarker];
// source.rotation = newRad;
}
Run Code Online (Sandbox Code Playgroud)
更新:我有旋转方法,但有没有办法旋转GMSMarker,因为没有转换方法.
如何在谷歌地图上旋转他们的车?
我们可以根据课程属性CLLocation Class旋转图像
let marker:GMSMarker = GMSMarker.init(position: currentLocation!)
let head = locationManager.location?.course ?? 0
marker.rotation = head
marker.icon = UIImage(named: "testyCar.png")
marker.map = mapView
Run Code Online (Sandbox Code Playgroud)
你可以做类似的事情 -
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
CLLocationDirection direction = newHeading.trueHeading;
lastDriverAngleFromNorth = direction;
self.driverMarker.rotation = lastDriverAngleFromNorth - mapBearing;
}
#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
mapBearing = position.bearing;
self.driverMarker.rotation = lastDriverAngleFromNorth - mapBearing;
}
Run Code Online (Sandbox Code Playgroud)
当前位置“ CLLocation”对象具有一个称为“ course”的属性
@property(readonly, nonatomic) CLLocationDirection course;
Run Code Online (Sandbox Code Playgroud)
类型为CLLocationDirection(double的typedef),它是位置的角度。
为了使汽车旋转,您需要在后端,方向以及纬度和经度上有额外的字段。通过在UIView上应用变换来使用此信息来旋转汽车
CGAffineTransformMakeRotation(M_PI * (course_of_location) / 180.0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10017 次 |
| 最近记录: |