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.
- (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. CLLocationDegrees is a double, which presents position in degrees
From documentation:
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.