【问题标题】:how to show an arrow on mapview showing the driving direction如何在地图视图上显示显示行车方向的箭头
【发布时间】:2013-12-02 07:28:44
【问题描述】:

我想在 GMSMapView 上显示一个箭头图像(我正在使用 google maps sdk)。 现在,如果我正在开车(箭头显示我当前的位置)并且我必须左转,那么我必须改变 mapView 的方位。但我不知道该怎么做。

我正在尝试更改 didUpdateHeading 中的方位

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
if(newHeading.headingAccuracy>0)
{

    float heading = newHeading.magneticHeading; //in degrees
     //heading = (heading*M_PI/180);
    //NSLog(@"heading=%f", heading);
    [mapView animateToBearing:heading];
}}

headingFilter 设置为 12。

我也尝试过 trueHeading,但磁头的效果更好,但并不准确。
请帮忙。

【问题讨论】:

  • 你试过[Your CLLocationManager instance].desiredAccuracy = kCLLocationAccuracyBestForNavigation吗?
  • 是的,locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

标签: ios iphone ios6 google-maps-sdk-ios gmsmapview


【解决方案1】:

您实际上不需要将任何内容转换为度数。您从委托方法获得的 newHeading 对象应该足够了。 GMS-reference for the animateToBearing: 需要 CLLocationDirection 作为参数。委托方法提供的 newHeading.magneticHeadingnewHeading.trueHeading 就是这种类型的对象。 另外:您正在将 newHeading 转换为浮点数,其中 CLLocationDirection 是双精度数,因此 GMS 函数也需要双精度数。 See reference.

【讨论】:

  • 我没有将其转换为度数。查看我发布的代码。甚至 [mapView animateToBearing:newHeading.magneticHeading];工作不正常
  • 对不起,我的意思是弧度。试试if(newHeading.headingAccuracy>0) { [mapView animateToBearing:newHeading]; }
  • 你试过这个吗??在 animateToBearing 中,我们可以传递 CLLocationDirection newHeading is of type CLHeading
  • mapView.animate(toBearing: newHeading.magneticHeading) - 工作正常
猜你喜欢
  • 2011-05-18
  • 2020-02-15
  • 1970-01-01
  • 2011-04-30
  • 2017-07-26
  • 2018-03-03
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
相关资源
最近更新 更多