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
You have to use NSString
conversion method doubleValue
. Have a look here: How to do string conversions in Objective-C?
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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.