关于C#:指针不能转换为’double’类型

Pointer cannot be cast to type 'double'

我想在地图上同时显示多个注释。 我的问题是我拥有NSString的所有纬度和经度......

我想将字符串转换为duble,以便我可以传递给"CLLocationCoordinate2D"实例。
但我收到的错误是:指针无法转换为'double'类型

1
2
locationCoordinate.latitude=(double)NearbyLocations.lat;
locationCoordinate.latitude=(double)NearbyLocations.lng;

这是我遇到问题的代码的一部分。 但是,你可能会看到我还没有完成它。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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];
//}

我该怎么做才能将点类型字符串转换为double


您必须使用NSString转换方法doubleValue。 看看这里:如何在Objective-C中进行字符串转换?


这意味着您正在尝试将NSNumber objective-c对象转换为C基元类型,这是不可能的。 要向字典添加整数,必须将其转换为NSNumber对象。 要把它拉出来,你必须将它转换回来:

1
2
locationCoordinate.latitude = [NearbyLocations.lat doubleValue];
locationCoordinate.latitude = [NearbyLocations.lng doubleValue];