2 u013958441 u013958441 于 2014.04.01 16:30 提问

IOS百度地图绘制行走轨迹
  • (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 520)];
    self.mapView.showsUserLocation = YES;
    [self.view addSubview:_mapView];
    [self configureRoutes];
    }

-(void)configureRoutes
{
// define minimum, maximum points定义最小值,最大值点
BMKMapPoint northEastPoint;

BMKMapPoint southWestPoint;

BMKMapPoint* pointArr = new BMKMapPoint[_locationPoint.count];

// char*str=(char )malloc(8);
就是卡死到这了!!!!! BMKMapPoint
pointArray = malloc(sizeof(CLLocationCoordinate2D) * _locationPoint.count);

for(int idx = 0; idx < _locationPoint.count; idx++)
{
    CLLocation *location = [_locationPoint objectAtIndex:idx];
    CLLocationDegrees latitude  = location.coordinate.latitude;
    CLLocationDegrees longitude = location.coordinate.longitude;

    // create our coordinate and add it to the correct spot in the array 创建我们的坐标数组中,并将它添加到正确的位置
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
    BMKMapPoint point = BMKMapPointForCoordinate(coordinate);

    // if it is the first point, just use them, since we have nothing to compare to yet. 如果是第一点,只使用他们,因为我们没有比较
    if (idx == 0) {
        northEastPoint = point;
        southWestPoint = point;
    } else {
        if (point.x > northEastPoint.x)
            northEastPoint.x = point.x;
        if(point.y > northEastPoint.y)
            northEastPoint.y = point.y;
        if (point.x < southWestPoint.x)
            southWestPoint.x = point.x;
        if (point.y < southWestPoint.y)
            southWestPoint.y = point.y;
    }

    pointArr[idx] = point;
}
//表示路由的数据点
if (self.routeLine) {
    //在地图上移除已有的坐标点
    [self.mapView removeOverlay:self.routeLine];
}

self.routeLine = [BMKPolyline polylineWithPoints:pointArr count:_locationPoint.count];

// add the overlay to the map.覆盖添加到地图
if (nil != self.routeLine) {
    [self.mapView addOverlay:self.routeLine];
}

// clear the memory allocated earlier for the points,清楚点的早些时候分配的内存
free(pointArr);

}

  • (BMKOverlayView*)mapView:(BMKMapView )map viewForOverlay:(id)overlay { if ([overlay isKindOfClass:[BMKPolyline class]]) { BMKPolylineView polylineView = [[[BMKPolylineView alloc] initWithOverlay:overlay] autorelease]; polylineView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:1]; polylineView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7]; polylineView.lineWidth = 3.0; return polylineView; } return nil; }
  • (void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation
    {
    CLLocation *location = [[CLLocation alloc] initWithLatitude:userLocation.coordinate.latitude
    longitude:userLocation.coordinate.longitude];

    // check the zero point检查零点
    if (userLocation.coordinate.latitude == 0.0f ||
    userLocation.coordinate.longitude == 0.0f)
    return;

    // check the move distance检查移动的距离
    if (_locationPoint.count > 0) {
    CLLocationDistance distance = [location distanceFromLocation:_currentLocation];
    if (distance < 5)
    return;
    }

    if (nil == _locationPoint) {
    _locationPoint = [[NSMutableArray alloc] init];
    }

    [_locationPoint addObject:location];
    _currentLocation = location;

    NSLog(@"points: +++++++++++++++++++++%@", _locationPoint);

    [self configureRoutes];

    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude);
    [self.mapView setCenterCoordinate:coordinate animated:YES];

}

-(void)viewWillAppear:(BOOL)animated {
[_mapView viewWillAppear];
_mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放

}

-(void)viewWillDisappear:(BOOL)animated {
[_mapView viewWillDisappear];
_mapView.delegate = nil; // 不用时,置nil

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)dealloc { [_mapView release]; [super dealloc]; }

@end
这是我参照高德地图的一个demo写的,到了动态分配内存的时候就卡那了,一直提示错误,解决不了,求大神帮忙。
BMKMapPoint* pointArray = malloc(sizeof(CLLocationCoordinate2D) * _locationPoint.count);

11个回答

luchenfeng199211
luchenfeng199211   2014.05.28 10:43

BMKMapPoint* pointArray = (BMKMapPoint *)malloc(sizeof(CLLocationCoordinate2D) * _locationPoint.count);试试

shangshang1029
shangshang1029   2015.04.21 16:18

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:18

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:18

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:18

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:18

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:19

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:19

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

shangshang1029
shangshang1029   2015.04.21 16:19

解决了吗, lz, 给说说吧,咱们用的是同一个东西,我也越到同样问题了

touch929
touch929   2015.05.07 15:48

大神们,我也遇到这个问题了,能给个DOME 看看,谢谢啦

共11条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片