[英]Pointer cannot be cast to type 'double'
I want to display more than one annotation on the map at the same time. 我想在地图上同时显示多个注解。 the problem that I have is that I have all latitude and longitude as NSString...
我遇到的问题是,我的纬度和经度都像NSString一样...
I want to convert strings to duble so that I can passed to "CLLocationCoordinate2D" instance.. but I get error which says:Pointer cannot be cast to type 'double' 我想将字符串转换为duble,以便可以传递给“ CLLocationCoordinate2D”实例。.但是我收到错误消息,该错误指出:指针不能强制转换为“ double”类型
locationCoordinate.latitude=(double)NearbyLocations.lat;
locationCoordinate.latitude=(double)NearbyLocations.lng;
This is a part of the code that I have problem with. 这是我有问题的代码的一部分。 However, as you might see that I haven't finished it yet.
但是,您可能会看到我还没有完成。
NSMutableArray *locations= [[NSMutableArray alloc]init];
CLLocationCoordinate2D locationCoordinate;
location *NearbyLocations;
Annotation *annotatedLocations;
//for (int i=0; i < locationOnMap.count;i++) {
annotatedLocations = [[Annotation alloc]init];
locationCoordinate.latitude=(double)NearbyLocations.lat;
locationCoordinate.latitude=(double)NearbyLocations.lng;
annotatedLocations.coordinate=locationCoordinate;
annotatedLocations.title=NearbyLocations.lo_name;
annotatedLocations.subtitle=NearbyLocations.lo_vicinity;
[locations addObject:annotatedLocations];
//}
What can I do to cast point typed string into double 我该怎么做才能将点型字符串转换为双精度型
You have to use NSString
conversion method doubleValue
. 您必须使用
NSString
转换方法doubleValue
。 Have a look here: How to do string conversions in Objective-C? 在这里看看: 如何在Objective-C中进行字符串转换?
This means you're trying to cast an NSNumber objective-c object to a C primitive type, which is not possible. 这意味着您正在尝试将NSNumber目标C对象强制转换为C基本类型。 To add an integer to a dictionary you have to convert it to an NSNumber object.
要将整数添加到字典中,必须将其转换为NSNumber对象。 To pull it out, you have to convert it back like this:
要拉出它,您必须像这样将其转换回:
locationCoordinate.latitude = [NearbyLocations.lat doubleValue];
locationCoordinate.latitude = [NearbyLocations.lng doubleValue];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.