1

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...

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'

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

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
Mohammed
  • 33
  • 1
  • 6

2 Answers2

4

You have to use NSString conversion method doubleValue. Have a look here: How to do string conversions in Objective-C?

Dov
  • 15,530
  • 13
  • 76
  • 177
akalenuk
  • 3,815
  • 4
  • 34
  • 56
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];
SmileBot
  • 19,393
  • 7
  • 65
  • 62