Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store CLLocationCoordinate2D?
    primarykey
    data
    text
    <p>I'm attempting to build an application that builds and saves routes similar to map my run. I'm using the <a href="https://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010048">Breadcrumb</a> sample code, specifically the <code>CrumbPath</code> and <code>CrumbPathView</code> as the base of my routes, from Apple. Two questions: </p> <ol> <li><p>If I try to access the <code>MKMapPoint *points</code> object of the <code>CrumbPath</code> like so:</p> <pre><code>[_route lockForReading]; NSLog(@"%@", _route.points); NSLog(@"%d", _route.pointCount); [_route unlockForReading]; </code></pre> <p>my app crashes, saying:</p> <pre><code>Thread 1: EXC_BAD_ACCESS (code: 1, address: 0x9450342d) </code></pre> <p>Which I have a hard time understanding, because within the <code>CrumbPath.m</code> file, the folks at apple write to the "array" by explicitly acquiring the write lock, and then unlocking it, but if I acquire the read lock and attempt to read from it, it crashes.</p></li> <li><p>The reason I attempt to access the <code>points</code> is in an attempt to get the <code>MKMapPoints</code>, convert them to <code>CLLocationCoordinate2D</code> objects, and save them so I can redraw the <code>polyline</code> at the user's request. Since I cannot get access to the <code>points</code>, I attempt to save the <code>CLLocationCoordinate2D</code> objects from my <code>locationManager</code> that I send to the <code>_route</code> in an array to upload to my <a href="http://parse.com">Parse</a> backend, but I always get an error saying:</p> <pre><code>Sending 'CLLocationCoordinate2D' to parameter of incompatible type 'id' </code></pre> <p>Which isn't making this any easier. Does anybody have any insight to why I'm getting these errors?</p></li> </ol> <p><strong>Location Manager Delegate</strong></p> <pre><code>-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { if (_userLocation.longitude != manager.location.coordinate.longitude &amp;&amp; _userLocation.latitude != manager.location.coordinate.latitude) { _userLocation = manager.location.coordinate; } if (_isRecording) { if (!_route) { NSLog(@"lat: %f, lng: %f", _userLocation.latitude, _userLocation.longitude); _route = [[CrumbPath alloc] initWithCenterCoordinate:_userLocation]; [_mapView addOverlay:_route]; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(_userLocation, 2000, 2000); [_mapView setRegion:region animated:YES]; }else { MKMapRect updateRect = [_route addCoordinate:_userLocation]; if (!MKMapRectIsNull(updateRect)) { MKZoomScale currentZoomScale = (CGFloat)(_mapView.bounds.size.width / _mapView.visibleMapRect.size.width); CGFloat lineWidth = MKRoadWidthAtZoomScale(currentZoomScale); updateRect = MKMapRectInset(updateRect, -lineWidth, -lineWidth); [_routeView setNeedsDisplayInMapRect:updateRect]; } } [_routePoints addObject:_userLocation]; [_route lockForReading]; NSLog(@"%d", _route.pointCount); NSLog(@"%@", _route.points); [_route unlockForReading]; } } </code></pre> <p><strong>Stop Recording Logic</strong></p> <pre><code> //stop recording NSLog(@"STOP"); if (_route) { NSLog(@"There is a route"); //Show route options toolbar [_route lockForReading]; NSLog(@"%@", _route); NSLog(@"%d", _route.pointCount); NSLog(@"%@", _route.points); PFObject *routeToSave = [PFObject objectWithClassName:@"Routes"]; //[routeToSave setObject:_route forKey:@"routePoints"]; [_route unlockForReading]; [routeToSave saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (!error) { NSLog(@"%c", succeeded); }else { NSLog(@"%@", error); } }]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload