MKMapPointForCoordinate返回点,x和y值设置为-1

时间:2014-10-12 17:42:00

标签: ios mapkit

我正在尝试使用一组位置坐标绘制叠加层,但是当我将每个坐标转换为MKMapPoint时,生成的点会将x和y值设置为-1

以下是我的代码片段

    idxGen = 0;
    for (idx2 = 0; idx2<[decodePoints count]; idx2++) {
        CLLocation *location = [decodePoints objectAtIndex:idx2];
        CLLocationCoordinate2D coord = location.coordinate;
        CLLocationCoordinate2D c = CLLocationCoordinate2DMake(coord.latitude, coord.longitude);
        MKMapPoint point = MKMapPointForCoordinate(coord);

        NSLog(@"%f, %f", c.latitude, c.longitude);

        if (idxGen == 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;
        }
        if (idxGen >= count) {
            count = count + baseCount/2;
            tempPointArr = malloc(sizeof(CLLocationCoordinate2D) * (count));
            memcpy(tempPointArr, pointArr, sizeof(CLLocationCoordinate2D) * idxGen);
            free(pointArr);
            pointArr = tempPointArr;
            tempPointArr = NULL;
        }
        routeSegmentPoints[routeSegmentIndex] = point;
        pointArr[idxGen] = point;
        idxGen++;
        routeSegmentIndex++;
    }
    SLRoute *route = [SLRoute routeWithPoints:routeSegmentPoints count:[decodePoints count]];
    [directionDict setObject:route forKey:@"route"];
    free(routeSegmentPoints);

}

这是我正在制作的日志

  

2014-10-12 15:22:37.533 Mappir [1814:200574] -99.174258,19.466190
  2014-10-12 15:22:37.534 Mappir [1814:200574] -99.173764,19.465703
  2014-10-12 15:22:37.534 Mappir [1814:200574] -99.173437,19.465442
  2014-10-12 15:22:37.535 Mappir [1814:200574] -99.173437,19.465442
  2014-10-12 15:22:37.535 Mappir [1814:200574] -99.173346,19.465369
  2014-10-12 15:22:37.536 Mappir [1814:200574] -99.172818,19.464496
  2014-10-12 15:22:37.536 Mappir [1814:200574] -99.171372,19.462071
  2014-10-12 15:22:37.537 Mappir [1814:200574] -99.170748,19.460947
  2014-10-12 15:22:37.537 Mappir [1814:200574] -99.170687,19.460857
  2014-10-12 15:22:37.538 Mappir [1814:200574] -99.170687,19.460857
  2014-10-12 15:22:37.538 Mappir [1814:200574] -99.170471,19.460543

1 个答案:

答案 0 :(得分:0)

idxGen在您的循环中不会发生变化,因此如果它不是0,那么您将永远不会将northEastPoint设置为MKMapPoint,如果它是0,您将始终将其设置为decodePoints中的最后一个MKMapPoint。

至于结果为-1的原因,您必须提供一些关于decodePoints中存储的值的提示。或许可以记录coord的值。