简体   繁体   English

适用于iOS的mapkit中的didupdateuserlocation方法?

[英]didupdateuserlocation method in mapkit for ios?

I m trying to give 5 annotations around user location MKMapView...I m choosing random values to annotations in my didupdateuserlocation method...when i run my projet all 5 annotations showing in a centre of the earth at a same place..its showing in sea area near to africa...anyone help me change different locations for annotations. 我试图在用户位置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];
    }

}

i printed my random values..they are 我打印了我的随机值..他们是

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

help me with this... 帮助我...

CLLocationCoordinate2D is a structure of two CLLocationDegrees. CLLocationCoordinate2D是两个CLLocationDegrees的结构。 CLLocationDegrees is a double, which presents position in degrees CLLocationDegrees是一个双精度值,以度为单位显示位置
From 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.

So latitude must be between -90 and 90, and longitude must be between -180 and 180. Your random position is to large, and mapkit shows you position 0, 0 which is in Gulf of Guinea. 因此,纬度必须在-90到90之间,而经度必须在-180到180之间。您的随机位置太大,而mapkit显示的位置是0、0,位于几内亚湾。

Maybe your values for lat and lon are not valid? 也许您的经纬度值无效? Try with this snippet 试试这个片段

CGFloat latDelta = userCoordinate.latitude+(i*0.000010);
CGFloat longDelta = userCoordinate.longitude+(i*0.000010);

The values that you have generated seems very strange for latitude and longitude! 对于纬度和经度,您生成的值似乎很奇怪! Example Berlin Cafe Kranzler has the values 示例Berlin Cafe Kranzler具有值

52.504039 13.330925 52.504039 13.330925

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM