如何根据设备指南针值旋转Google地图?

时间:2013-07-03 10:57:50

标签: iphone ios objective-c google-maps-sdk-ios

我正在使用适用于iOS的最新Google Map SDK,我无法像下面那样旋转地图。

对于Eg。 MKMapview能够使用Compass Heading旋转它。

[mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];

所以我的问题是,是否有任何好友帮助我找出如何在Google MAP SDK中完成这项工作。

我已经提到了有关Google Map SDK的所有内容,我找不到任何此类属性或任何方法来根据Device Compass值旋转Map。

我已经提到了这个关于Compass值的链接,但我找不到任何与之相关的内容。

https://developers.google.com/maps/documentation/ios/map

4 个答案:

答案 0 :(得分:5)

似乎Google Maps iOS SDK中没有此功能的直接步骤。您可以通过组合以下两个函数来实现所需的效果:

1,偶尔使用locationManager:didUpdateHeading:读取当前方位。 Check this post查看用法

2,当您获得新的轴承值时,请使用[mapView_ animateToBearing:x];

设置轴承

答案 1 :(得分:0)

通过结合上面帖子中的所有链接,以下是尝试旋转GoogleMaps iOS SDK,它对我来说很好用

首先创建一个CLLocationManager

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    locationManager.distanceFilter=kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];

    [locationManager startUpdatingHeading];

并使用CLLocationManager的{​​{1}}方法在标题发生变化时调用委托方法startUpdatingHeading。现在,您可以使用以下代码根据标题更改旋转地图。

- (void)locationManager:(CLLocationManager *)manager  didUpdateHeading:(CLHeading *)newHeading

答案 2 :(得分:0)

SWIFT 3.0

需要设置位置管理器并调用startUpdatingHeading:

class NavegacaoRotaViewController: UIViewController ,GMSMapViewDelegate,CLLocationManagerDelegate

...

self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.startUpdatingHeading()

然后包含以下委托方法,您应该能够从newHeading中提取标题角度:

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
            googleMapsView.animate(toBearing: newHeading.trueHeading)
}

<强>的OBJ-C

需要设置位置管理器并调用startUpdatingHeading:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingHeading];

然后包含以下委托方法,您应该能够从newHeading中提取标题角度:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
  NSLog(@"Updated heading: %@", newHeading);
}

答案 3 :(得分:0)

地图旋转 swift 5.0

 func intlizeLocationManager(){
    locationManager = CLLocationManager()
    handleArea.delegate = self
    handleArea.settings.myLocationButton = true
    locationManager?.delegate = self
    locationManager?.requestAlwaysAuthorization()
    locationManager?.desiredAccuracy = kCLLocationAccuracyBestForNavigation
    locationManager.distanceFilter = kCLDistanceFilterNone
    locationManager?.requestWhenInUseAuthorization()
    locationManager?.allowsBackgroundLocationUpdates = true
    locationManager?.startUpdatingLocation()
    locationManager.startMonitoringSignificantLocationChanges()
    locationManager.startUpdatingHeading()

}

 func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
    let head = newHeading.trueHeading
    map.animate(toBearing: head)
}