到目前为止,我已经尝试生成随机纬度和经度并使用“CLLocationCoordinate2DIsValid”对其进行验证。但问题是我从来没有得到我指定的“CLCircularRegion”内的坐标。以下是我写的逻辑:
CLLocationCoordinate2D myCoordinates = { currentLocationLatitude, currentLocationLongitude };
CLCircularRegion *myRegion = [[CLCircularRegion alloc] initWithCenter:myCoordinates radius:160934 identifier:@"myID"];
for (int i=0; i< 15; i++) {
double latitude = (arc4random()%20) + (myCoordinates.latitude);
double longitude = (myCoordinates.longitude) + arc4random()%10;
CLLocationCoordinate2D randomCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
if(CLLocationCoordinate2DIsValid(randomCoordinate) != NO)
{
NSLog(@"randomCoordinate: %f %f", randomCoordinate.latitude, randomCoordinate.longitude);
if([myRegion containsCoordinate:randomCoordinate])
{
NSLog(@"Point contains inside your region.");
}
}
}
这个实现有什么问题还是有其他方法可以找到随机点?