在蓝色脉动点(用户当前位置)上显示航向,而不会丢失精度圆

发布于 2024-12-04 10:37:24 字数 853 浏览 0 评论 0原文

我有一个 CLLocation 管理器,如下所示

myLocation = [[CLLocationManager alloc] init];
    myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
    myLocation.delegate=self;

,如果设备支持标题信息,则调用方法来更新标题

if([CLLocationManager headingAvailable])
        [myLocation startUpdatingHeading];

,并从以下方法检索标题更改,

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    [mymap setTransform:CGAffineTransformMakeRotation(-1 * newHeading.trueHeading * 3.14159 / 180)];

}   

我可以使用此信息(newHeading.trueHeading)来旋转地图。但是,我如何在蓝点(用户当前位置的指示器)上显示一个以给定或强制精度描绘前进方向的扇区。我可以使用蓝点的自定义图像,但它会失去光“精度圈”。有什么方法可以获取蓝点视图的引用并修改它,这样精度圆就不会丢失。

此外,可以通过负旋转来避免注释的旋转,但是当地图旋转时,注释的“标题”和“副标题”会延伸到可见屏幕的视图之外。有什么办法可以将它们限制在地图视图中吗?

感谢您提前提供的任何帮助

I have a CLLocation manager as follows

myLocation = [[CLLocationManager alloc] init];
    myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
    myLocation.delegate=self;

if device supports heading information then method is called to update heading

if([CLLocationManager headingAvailable])
        [myLocation startUpdatingHeading];

and change in heading are retrieved from following method

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    [mymap setTransform:CGAffineTransformMakeRotation(-1 * newHeading.trueHeading * 3.14159 / 180)];

}   

I can use this information (newHeading.trueHeading) to rotate the map. But how can I show a sector that will depict heading direction with given or forced accuracy, on blue dot (indicator of users current location). I am able to use custom image for blue dot but it looses light "accuracy circle" then. Is there any way to get a reference to the blue dot view and modify it, so that accuracy circle is not lost.

Also rotation of annotations can be avoided with negative rotation but when map is rotating the "Title" and "subTitle" of annotations gets extended beyond view of visible screen. Is there any way to limit them to map's view.

Thanks for any help in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乙白 2024-12-11 10:37:24

您可以使用此项目作为指南。它会旋转整个地图视图,但您可以将其推断到您的视图。

编辑:如果您想自定义 userLocation 注释,您必须实现 viewForAnnotation 并检查给定注释是否为 MKUserLocation 并返回根据需要配置的自定义注释视图。

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        //Configure your custom view to point to the current heading and return it.

    }

}

You can use this project as a guide. It rotates the whole mapView, but you can extrapolate it to your view.

EDIT: If you want to customize the userLocation annotation you have to implement viewForAnnotation and check if the given annotation is MKUserLocation and return a custom annotationView configured as you want.

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        //Configure your custom view to point to the current heading and return it.

    }

}
难以启齿的温柔 2024-12-11 10:37:24
    - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
        if (newHeading.headingAccuracy > 0) {
                // [newHeading retain];
             float heading = newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading;


             [mymap setTransform:CGAffineTransformMakeRotation(heading)];


        }
    }
    - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
        if (newHeading.headingAccuracy > 0) {
                // [newHeading retain];
             float heading = newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading;


             [mymap setTransform:CGAffineTransformMakeRotation(heading)];


        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文