2012-01-02 32 views
0

我嘗試給用戶位置附近的5個註釋MKMapView ...我選擇隨機值註釋在我的didupdateuserlocation方法...當我運行我的projet所有5個註釋顯示在同一個地方的地球中心。 。它顯示在非洲附近的海域...任何人都可以幫助我更改不同的位置進行註釋。mapup for ios中的didupdateuserlocation方法?

- (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]; 
    } 

} 

我印我的隨機values..they是

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

謝謝你們......在我的數據模型,我爲座標爲readonly..so說我不能改變我的值,直到now.i發現了一個屬性,清除我的問題..不管怎樣,謝謝你們兩位:-) .. – 2012-01-02 16:33:47

回答

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位置。

+0

你是對的......但我給出了下面這個值來檢查我是否在自己的註解中獲得註釋..CLLocationCoordinate2D newCoord = {12.344654,-15.756767};但我仍然在我的地圖中獲得相同的地方。 – 2012-01-02 16:14:39

1

也許你的經緯度和經度值是無效的?試試這個片段

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

您已經生成的值對於經緯度來說似乎很奇怪!例如柏林咖啡廳柯蘭茲勒的值有

52.504039 13.330925