如何将我旅行的路线图信息保存到ios

时间:2015-10-20 10:04:48

标签: ios objective-c sqlite mkmapview mkpolyline

我是iOS的新手,并且正在使用谷歌地图。

我想将我的旅行路线图(使用折线)保存到我的数据库中,例如 Runtastic 应用程序。

当我搬家时,目前正在获取折线。

这是我使用的代码。

 - (void)startLocationUpdates
   {

     if (self.locationManager == nil) {
        self.locationManager = [[CLLocationManager alloc] init];
    }

   self.locationManager.delegate = self;
   self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
   self.locationManager.activityType = CLActivityTypeFitness; 
   self.locationManager.distanceFilter = 8; // meters
   [self.locationManager startUpdatingLocation];

  }

  - (void)locationManager:(CLLocationManager *)manager
    didUpdateLocations:(NSArray *)locations
  {

   for (CLLocation *newLocation in locations) {

    if (self.locations.count > 0) {

        self.distance += [newLocation distanceFromLocation:self.locations.lastObject];            
        CLLocationCoordinate2D coords[2];
        coords[0] = ((CLLocation *)self.locations.lastObject).coordinate;
        coords[1] = newLocation.coordinate;            
        MKCoordinateRegion region =
        MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 300, 300);
        [self.mapView setRegion:region animated:YES];            
        [self.mapView addOverlay:[MKPolyline polylineWithCoordinates:coords count:2]];

    }

    [self.locations addObject:newLocation];

     }
  }
 - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id    < MKOverlay >)overlay
  {
  if ([overlay isKindOfClass:[MKPolyline class]]) {
    MKPolyline *polyLine = (MKPolyline *)overlay;
    MKPolylineRenderer *aRenderer = [[MKPolylineRenderer alloc] initWithPolyline:polyLine];
    aRenderer.strokeColor = [UIColor blueColor];
    aRenderer.lineWidth = 3;
    return aRenderer;
}
return nil;

}

现在我希望将地图详细信息保存到数据库中并再次检索它并将其显示为MapView。

提前谢谢。

0 个答案:

没有答案