地图视图注释调整

发布于 2024-10-26 02:22:09 字数 1304 浏览 5 评论 0原文

大家好,当用户输入以下代码时,我正在尝试更改注释图像

- (void)locationManager:(CLLocationManager *)manager   didUpdateToLocation:(CLLocation *)newLocation  fromLocation:(CLLocation *)oldLocation
{
    for (int i = 0; i < [_annotationArray count]; i++)
    {
        //MKAnnotation xxx = [_annotationArray objectAtIndex:i];

        Shadows* shadowObj2 = [_shadowArray objectAtIndex:i];

        NSLog(@"%@",_shadowArray);

        CLLocationCoordinate2D location3;

        location3.latitude  =  [shadowObj2.position_x floatValue];
        location3.longitude =  [shadowObj2.position_y floatValue];

        CLLocation* locationold = [[CLLocation alloc] initWithLatitude:location3.latitude longitude:location3.longitude];

        CLLocationDistance kilometers = [newLocation distanceFromLocation:locationold];

        //temp = [kilometers intValue];

        if (kilometers > 50 && kilometers <100)
        {
            MKAnnotationView* newA = [[MKAnnotationView alloc] initWithAnnotation:[_annotationArray objectAtIndex:i] reuseIdentifier:@"annotation1"];
            newA.image = [UIImage imageNamed:@"shadowS.png"];
            newA.canShowCallout = YES;
        }

        [locationold release];
        //[shadowObj2 release];
    }

}

,但我无法更改注释图像,请告诉我为什么我无法做到这一点

HI all i am trying to change the image of annotation when user walk in following code

- (void)locationManager:(CLLocationManager *)manager   didUpdateToLocation:(CLLocation *)newLocation  fromLocation:(CLLocation *)oldLocation
{
    for (int i = 0; i < [_annotationArray count]; i++)
    {
        //MKAnnotation xxx = [_annotationArray objectAtIndex:i];

        Shadows* shadowObj2 = [_shadowArray objectAtIndex:i];

        NSLog(@"%@",_shadowArray);

        CLLocationCoordinate2D location3;

        location3.latitude  =  [shadowObj2.position_x floatValue];
        location3.longitude =  [shadowObj2.position_y floatValue];

        CLLocation* locationold = [[CLLocation alloc] initWithLatitude:location3.latitude longitude:location3.longitude];

        CLLocationDistance kilometers = [newLocation distanceFromLocation:locationold];

        //temp = [kilometers intValue];

        if (kilometers > 50 && kilometers <100)
        {
            MKAnnotationView* newA = [[MKAnnotationView alloc] initWithAnnotation:[_annotationArray objectAtIndex:i] reuseIdentifier:@"annotation1"];
            newA.image = [UIImage imageNamed:@"shadowS.png"];
            newA.canShowCallout = YES;
        }

        [locationold release];
        //[shadowObj2 release];
    }

}

But i am unable to change annotation image please tell me why i am not able to do it

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

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

发布评论

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

评论(2

孤凫 2024-11-02 02:22:09

我不认为这段代码与地图视图有任何联系,并且您正在使用新图像分配 MKAnnotationView 的新实例。这不会改变地图上已有的现有内容。您需要做的是检查地图视图视图中的注释距离,然后更改其图像。

I don't think this code has any connection with the map view and u are allocating a new instance of MKAnnotationView with the new image. This doesn't change the existing ones which you already have on the map. What you need to do is check the distance in mapview's view for annotation and then change its image there.

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