【发布时间】:2016-01-03 05:29:44
【问题描述】:
我正在使用google map ios sdk,我的问题是我必须在地图的折线上获取每1000米的坐标。现在我能够获取给定路径中的位置数量,并能够使用以下代码片段访问它们。
-(NSMutableArray*)getCoordinates {
pathCoordinatesArray = [[NSMutableArray alloc]init];
GMSMutablePath *path = [VTDirectionManager getPath];
NSLog(@"count %d",path.count);
for (int i=0 ; i<path.count; i++) {
if (i+1 > path.count) {
return pathCoordinatesArray;
}
for (int j = i+1; j<path.count; j++) {
CLLocationCoordinate2D sourceCoordinate = [path coordinateAtIndex:i];
CLLocation *sourceLocation = [[CLLocation alloc]initWithLatitude:sourceCoordinate.latitude longitude:sourceCoordinate.longitude];
CLLocationCoordinate2D destinationCoordinate = [path coordinateAtIndex:j];
CLLocation *destinationLocation = [[CLLocation alloc]initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
BOOL check ;
check = [self checkDistanceForSource:sourceLocation andDestination:destinationLocation];
//jump to next 1000 distance position
if (check) {
i = j;
}
}
}
return pathCoordinatesArray;
}
-(BOOL)checkDistanceForSource:(CLLocation*)source andDestination:(CLLocation*)destination {
CLLocationDistance distance = [source distanceFromLocation:destination];
if (distance > 1000) {
CLLocation *location = [[CLLocation alloc] initWithLatitude:destination.coordinate.latitude longitude:destination.coordinate.longitude];
[pathCoordinatesArray addObject:location];
return YES;
}
return NO;
}
假设如果我有 5000 米的距离路径,那么我必须得到 5 个坐标,每个坐标依次位于 1000 米的位置。
我认为这是错误的代码。建议我优化代码
看图片每个点都是1000米的距离。
【问题讨论】:
-
你能澄清你的问题吗?
-
@jogendra : 我需要在 A 点和 B 点之间获取每 1000 米的坐标
-
@jogendra:我用一些代码更新了我的问题,请检查一下。我认为这是错误的代码。建议我优化代码
-
你在数组 pathCoordinatesArray 中的坐标 .. 对吗?
-
该数组中的坐标的距离均大于或等于 1000。最后,我必须在该数组中存储坐标,每个坐标都为 1000 或更大,然后在 pointA 和 pointB 之间
标签: ios objective-c google-maps google-maps-api-3