1

我想同时在地图上显示多个注释。我遇到的问题是我将所有纬度和经度都作为 NSString ...

我想将字符串转换为双精度,以便可以传递给“CLLocationCoordinate2D”实例。但我收到错误消息:指针不能转换为“双精度”类型

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

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

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];
//}

我该怎么做才能将点类型的字符串转换为双精度

4

2 回答 2

4

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

于 2013-08-01T14:27:37.083 回答
2

This means you're trying to cast an NSNumber objective-c object to a C primitive type, which is not possible. To add an integer to a dictionary you have to convert it to an NSNumber object. To pull it out, you have to convert it back like this:

locationCoordinate.latitude = [NearbyLocations.lat doubleValue];
locationCoordinate.latitude = [NearbyLocations.lng doubleValue];
于 2014-03-24T16:17:47.057 回答