错误:从不兼容的类型“ id”分配给“ CLLocationCoordinate2D” [英] Error : Assigning to 'CLLocationCoordinate2D' from incompatible type 'id'

查看:95
本文介绍了错误:从不兼容的类型“ id”分配给“ CLLocationCoordinate2D”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai我正在尝试在mkmap中显示多个注释。在添加坐标时,它显示错误:从不兼容的类型 id分配给 CLLocationCoordinate2D。我知道这是一个简单的问题,但是我已经搜索了很多次并尝试了很多,但是没有用,我的代码是

Hai I am trying to display multiple annotations in mkmap. While am adding the coordinates it shows the error:"Assigning to 'CLLocationCoordinate2D' from incompatible type 'id'". I know this is a simple prob, but I have searched many times and tried a lot but none works, my code is,

for(int i=0 ; i<coordinates.count ; i++)
    {
     MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
     point.coordinate =[coordinates objectAtIndex:i]; //here it shows the error
     point.title = @"title";
     [self.mapView addAnnotation:point];
    }

请劝我解决此问题。谢谢...

kindly advice me to solve this prob. Thank you...

推荐答案

由于 CLLocationCoordinate2D 不是目标, C对象,但为 struct ,它不能直接存储在 NSArray 对象中,而必须包装在其中 NSValue 对象。

As CLLocationCoordinate2D is not an Objective-C object, but a struct, it cannot be directly stored in an NSArray object, but rather it must be wrapped within an NSValue object.

因此,从数组中读取坐标的代码可能是

Therefore the code to read co-ordinates from the array is probably:

CLLocationCoordinate2D coords;
[[coordinates objectAtIndex:i] getValue:&coords];
point.coordinate = coords;

但是要确定,我需要查看数组的创建方式。

However to know for sure, I would need to see how the array was created.

这篇关于错误:从不兼容的类型“ id”分配给“ CLLocationCoordinate2D”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆