objective-c - ios 的 mapkit 中的 didupdateuserlocation 方法?

标签 objective-c ios xcode mkmapview mapkit

我正在尝试围绕用户位置 MKMapView 提供 5 个注释...我在我的 didupdateuserlocation 方法中为注释选择随机值...当我运行我的项目时,所有 5 个注释都显示在同一位置的地球中心..它显示在非洲附近的海域...任何人都可以帮助我更改不同的注释位置。

- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation
{
    CLLocationCoordinate2D userCoordinate = userLocation.location.coordinate;
    for(int i = 1; i<=5;i++)

    {
        CGFloat latDelta = rand()*.035;       ///RAND_MAX -5.0;
        NSLog(@"%f",latDelta);
        CGFloat longDelta = rand()*.03;       ///RAND_MAX -5.0;
        NSLog(@"%f",longDelta);
        CLLocationCoordinate2D newCoord = { userCoordinate.latitude + latDelta, userCoordinate.longitude + longDelta };
        MapPoint *mp = [[MapPoint alloc] initWithCoordinate:newCoord title:[NSString stringWithFormat:@"Azam Home %d",i] subTitle:@"Home Sweet Home"];    
        [mv addAnnotation:mp];
    }

}

我打印了我的随机值..它们是

2012-01-02 20:27:32.229 ShareImg[749:15803] 588.244995
2012-01-02 20:27:32.230 ShareImg[749:15803] 8474257.000000
2012-01-02 20:27:32.231 ShareImg[749:15803] 56792752.000000
2012-01-02 20:27:32.231 ShareImg[749:15803] 29548310.000000
2012-01-02 20:27:32.231 ShareImg[749:15803] 40043812.000000
2012-01-02 20:27:32.231 ShareImg[749:15803] 14106338.000000
2012-01-02 20:27:32.231 ShareImg[749:15803] 3535964.000000
2012-01-02 20:27:32.232 ShareImg[749:15803] 43735528.000000
2012-01-02 20:27:32.232 ShareImg[749:15803] 51057228.000000
2012-01-02 20:27:32.232 ShareImg[749:15803] 60217132.000000

帮我解决这个...

最佳答案

CLLocationCoordinate2D 是两个 CLLocationDegrees 的结构。 CLLocationDegrees 是 double ,以度数表示位置
来自 documentation :

latitude
The latitude in degrees. Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator.
longitude
The longitude in degrees. Measurements are relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian.

所以纬度必须在 -90 到 90 之间,经度必须在 -180 到 180 之间。你的随机位置太大了,mapkit 显示你的位置 0, 0 在几内亚湾。

关于objective-c - ios 的 mapkit 中的 didupdateuserlocation 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8702623/

相关文章:

objective-c - 堆栈跟踪中方法名称旁边的数字是什么?

xcode - 在 monodevelop 中查看 plist 原始 xml

ios - iOS 中的 GCM(Google Cloud Messaging)(通知和数据负载。)

android - 如何使用 appcelerator 在运行时更改语言应用程序

iphone - 我可以将 ObjectiveC @selector 放入 NSDictionary 中吗?

iphone - 文本字段数组边界之外的 UIAlertView 错误但未使用文本字段

ios - 从 webView 返回后 PDF 无法加载

objective-c - 沙盒应用程序,通过引用包含文件?

ios - 使用 MPMoviePlayerController 时的内存泄漏

ios - 将 NSString 从一个类传递到另一个类。 (ECSlidingViewController?)