2

私はiOSが初めてで、Googleマップに取り組んでいます。

Runtastic Applicationなどのデータベースに、旅行したルート マップ (ポリライン付き) を保存したいと考えています。

現在、移動中にポリラインを取得しています。

これは私が使用するまでのコードです。

 - (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