ios - 在某个区域创建一个随机的 CLLocation 坐标

标签 ios objective-c random dictionary

我有一个 MKMapRect

我如何在里面创建一个随机的CLLocationCoordinate

我知道有 arc4random(),但如何将它用于 GPS 坐标?

最佳答案

#define ARC4RANDOM_MAX      0x100000000
... 

//val is a double between 0 and 1
double xOffset = ((double)arc4random() / ARC4RANDOM_MAX);
double yOffset = ((double)arc4random() / ARC4RANDOM_MAX);
MKMapPoint randomPoint;

randomPoint.x = maprect.origin.x + xOffset*maprect.size.width;
randomPoint.y = maprect.origin.y + yOffset*maprect.size.height;

CLLocationCoordinate2D randomCoordinate = MKCoordinateForMapPoint(randomPoint);

关于ios - 在某个区域创建一个随机的 CLLocation 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16508356/

相关文章:

ios - 使用 UIImagePickerController 减少内存使用

ios - Xamarin.Forms ZXing.Net.Mobile 在 iOS 10 上扫描结果后丢失当前页面

ios - 如何从UICollectionView访问outlet到UICollectionReusableView?

ios - Cross Directional UIScrollViews - 我可以修改滚动行为吗?

ios - 在自定义 UITableViewCell 中调整 UILabel 大小的问题

java - 您可以使用 java.util.Random 找到以前生成的随机数吗?

ruby - 如何在 Ruby 中随机取一段字符串?

ios - 在没有 Mac 的情况下将 Ionic 应用程序提交到 Apple App Store

iphone - 触摸 UIView 之外

python - `numpy.random.normal` 在不同的系统上生成不同的数字