User Tools

Site Tools


ios-labs-s14:class-08

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ios-labs-s14:class-08 [2014/02/26 14:03]
mbarboi
ios-labs-s14:class-08 [2014/02/28 14:55] (current)
mbarboi
Line 216: Line 216:
   -Have it implement the protocol MKAnnotation by typing "<​MKAnnotation>"​ immediately after the superclass name in the header file   -Have it implement the protocol MKAnnotation by typing "<​MKAnnotation>"​ immediately after the superclass name in the header file
   -Import it into MapRoot   -Import it into MapRoot
 +  -Add the following properties to the header file
  
-When the user touches the trips button (the car icon) you should add the annotations. The method for adding annotations to a map is called //​addAnnotation//​. Create a new annotation object for each coordinate and add it to the map.+<​code>​ 
 +@property (nonatomic, copy) NSString * title; 
 +@property (nonatomic, copy) NSString * subtitle; 
 +@property (nonatomic, assign) CLLocationCoordinate2D coordinate;​ 
 +</​code>​ 
 + 
 +When the user touches the trips button (the car icon) you should add the annotations. The method for adding annotations to a map is called //​addAnnotation//​. Create a new annotation object for each start and stop coordinate and add it to the map. 
 + 
 +Note that the property called coordinate on the annotation object is of type CLLocationCoordinate2D-- you cannot pass the GPSCoordinate object! Instead, convert the lat and long from the GPSCoordinate object to the following helper function: 
 + 
 +  CLLocationCoordinate2DMake(LAT,​ LONG); 
 +   
 +Which returns an object of type CLLocation2D
  
 ====Create Overlay==== ====Create Overlay====
Line 243: Line 256:
     //note the array is a C array     //note the array is a C array
     for(int i = 0; i < [points count]; i++) {     for(int i = 0; i < [points count]; i++) {
-        ​GPSCoordinates ​*coordinate = [points objectAtIndex:​i];​ +        ​GPSCoordinate ​*coordinate = [points objectAtIndex:​i];​ 
-        MKMapPoint point = MKMapPointForCoordinate(coordinate.coordinate);+         
 +        double lat = [coordinate.lat doubleValue];​ 
 +        double lon = [coordinate.lon doubleValue];​ 
 +        ​ 
 +        MKMapPoint point = MKMapPointForCoordinate(CLLocationCoordinate2DMake(lat,​ lon));
         pointArray[i] = point;         pointArray[i] = point;
     }     }
Line 258: Line 275:
 Call //​drawRouteForCoordinates//​ for each trip. Pass it the array of GPSCoordinate objects from the Trip object. Call //​drawRouteForCoordinates//​ for each trip. Pass it the array of GPSCoordinate objects from the Trip object.
  
 +----
 =====Conclusion===== =====Conclusion=====
 CoreData will not be that useful everyday, but if you ever have to write an app that has to deal with a **large** dataset it will make your life a lot easier. If you nail down the basics and make some nice wrapper methods for the data objects, it can also make Model management far easier. CoreData will not be that useful everyday, but if you ever have to write an app that has to deal with a **large** dataset it will make your life a lot easier. If you nail down the basics and make some nice wrapper methods for the data objects, it can also make Model management far easier.
ios-labs-s14/class-08.1393445037.txt.gz · Last modified: 2014/02/26 14:03 by mbarboi