didupdateuserlocation方法

didupdateuserlocation方法

我正在尝试在用户位置MKMapView周围给出5个注释...我在didupdateuserlocation方法中为注释选择了随机值...当我运行我的Projet时,所有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是一个双精度值,以度为单位显示位置
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/

10-08 21:18