求助!关于百度地图轨迹回放功能的实现


我是搞IOS开发的新手,刚刚带我的人给了我一个任务,就是把获取到的定位记录集,转化成地图上的点,然后按时间顺序,每隔1s显示一个大头针,并把两点连成线。其实显示效果就是像动画一样,把历史轨迹播放出来。

       我现在纠结的是把点按顺序显示出来,我在循环中添加[NSThread sleepForTimeInterval:1.0],但它并没有出现预期的效果,而是当我讲所有的大头针都加到地图中,才开始调用mapView:viewForAnnotation:来显示。。。苦思不得其解,希望大家能够帮帮忙,小女子万分感谢!

      第一次发帖,可能问题描述的不够清楚,大家可以给我提下意见哈,谢谢了!!!

代码如下:
-(void)getHistoryLocation
{
    NSString *tempSessionId = [ESLoginParser getSessionId];
    NSString *tempMobileNumber = m_Userinfo.mgrUserMobile;

    NSString *url = TRACKBACK_URL(tempSessionId, tempMobileNumber, mDateLabel.text);
    [ApplicationDelegate showWaitView"正在获取记录,请稍候..."];
    [ApplicationDelegate.esNetworkEngine get:url
                                      params:nil onCompletion:^(NSString* retString){
                                          [ApplicationDelegate hideWaitView];

                                          //清空原来的覆盖物
                                          NSArray* annotations = [NSArray arrayWithArray:_mapView.annotations];
                                          [_mapView removeAnnotations:annotations]; //会把“我的位置”清除
                                          NSArray* overlays = [NSArray arrayWithArray:_mapView.overlays];
                                          for (BMKShape* overlay in overlays) {
                                              if([overlay isKindOfClass:[BMKPolyline class]]){
                                                  [_mapView removeAnnotation:overlay];
                                              }
                                          }
                                         if([retString rangeOfString"</list>"].length > 0)
                                          { //分析返回结果
                                              ESLocationPointParser *parser = [[ESLocationPointParser alloc] init];
                                              NSArray *pointList = [parser parseResponse:retString];
                                              LngLatConverter * llc = [[LngLatConverter alloc] init];
                                              [llc translate:pointList converteType:GPS2BAIDU onCompletion:^(ESConverteResult *converteResult) {
                                                  //
                                                  if(converteResult.resultCode == SUCCESS){
                                                      if(pointList.count == 0){
                                                          [gutil alert"没有找到定位记录"];
                                                          return;
                                                      }    
                                                  }

                                                  double minLatitude = 999.0f;
                                                  double minLongitude = 999.0f;
                                                  double maxLatitude = 0.1f;
                                                  double maxLongitude = 0.1f;

                                                  int i = 0;
                                                  for (ESLocationPoint *point in pointList){
                                                      NSLog(@"%d",i);
                                                      CLLocationCoordinate2D coordinate = {[point.latitude doubleValue], [point.longitude doubleValue]};

                                                      //大头针信息
                                                      ESMarkerAnnotation* item = [[ESMarkerAnnotation alloc] init];
                                                      item.coordinate = coordinate;
                                                      item.title = point.updateTime; //point.address;
                                                      if(point.stayTime.length == 0){
                                                          item.subtitle = @"停留时间:1分钟";
                                                      }else{
                                                          item.subtitle = [NSString stringWithFormat"停留时间:%@分钟", point.stayTime];
                                                      }

                                                      //地图范围
                                                      if(coordinate.latitude < minLatitude){
                                                          minLatitude = coordinate.latitude;
                                                      }
                                                      if(coordinate.longitude < minLongitude){
                                                          minLongitude = coordinate.longitude;
                                                      }
                                                      if(coordinate.latitude > maxLatitude){
                                                          maxLatitude = coordinate.latitude;
                                                      }
                                                      if(coordinate.longitude > maxLongitude){
                                                          maxLongitude = coordinate.longitude;
                                                      }

                                                      if(i > 1){
                                                          BMKCoordinateRegion region;
                                                          region.center.latitude  = (minLatitude + maxLatitude)/2;
                                                          region.center.longitude = (minLongitude + maxLongitude)/2;
                                                          region.span.latitudeDelta = (maxLatitude-minLatitude);
                                                          region.span.longitudeDelta = (maxLongitude - minLongitude);

                                                          [_mapView setRegion:region animated:YES];

                                                      }else{ // == 1
                                                          CLLocationCoordinate2D coordinate = {minLatitude, minLongitude};
                                                          [_mapView setCenterCoordinate:coordinate animated:YES];
                                                      }

                                                      //添加大头针
                                                      [_mapView addAnnotation:item];
                                                      [NSThread sleepForTimeInterval:1.0];

                                                      //显示刚定位信息
                                                      if(myLocationAnnotation != nil){
                                                          [_mapView addAnnotation:myLocationAnnotation];
                                                      }

                                                      i++;
                                                  }
                                                }];
                                          }else{
                                              [gutil alert"返回结果不对"];
                                          }
                                      }
                                     onError:^(NSError* error){
                                         [ApplicationDelegate hideWaitView];
                                         [gutil alert:[error localizedDescription]];
                                     }];

}


- (BMKAnnotationView*) mapView: (BMKMapView*) mapView viewForAnnotation: (id<BMKAnnotation>) annotation{
    NSLog(@"tt");
    if([annotation isKindOfClass:[ESMarkerAnnotation class]]){
        BMKAnnotationView* newAnnotation=[[BMKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: annotation.title];
        newAnnotation.canShowCallout=YES;
        newAnnotation.image=[UIImage imageNamed"map_mark"];
        return newAnnotation;
    }else if ([annotation isKindOfClass:[ESMyLocationAnnotation class]]){
        BMKAnnotationView* newAnnotation=[[BMKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: annotation.title];
        newAnnotation.canShowCallout=YES;
        newAnnotation.image=[UIImage imageNamed"map"];
        return newAnnotation;
    }
    return nil;
}


1 个解决方案

#1


大家帮帮忙吧
智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告