2

我是 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。

先感谢您。

4

0 回答 0