我试图围绕用户位置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
帮助我...
答案 0 :(得分:2)
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位置。
答案 1 :(得分:1)
也许你的lat和lon值无效?尝试使用此代码段
CGFloat latDelta = userCoordinate.latitude+(i*0.000010);
CGFloat longDelta = userCoordinate.longitude+(i*0.000010);
您生成的值对于纬度和经度来说似乎很奇怪!示例Berlin Cafe Kranzler的值为
52.504039 13.330925