I「M在我的應用程序中使用MapKit與獲取用戶位置座標與MapKit
[mapview setShowUserLocation:YES];
我想設置region.center.latitude和region.center.longitude用的座標disaply用戶位置用戶位置,該怎麼辦呢
I「M在我的應用程序中使用MapKit與獲取用戶位置座標與MapKit
[mapview setShowUserLocation:YES];
我想設置region.center.latitude和region.center.longitude用的座標disaply用戶位置用戶位置,該怎麼辦呢
這裏是我的回答,我嘗試類似的東西和它的工作:
//inside my ViewDidLOad
locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D loc = [newLocation coordinate];
[maptView setCenterCoordiante:loc];
}
我覺得這個回答你的問題:? Returning Mapkit Userlocation Coordinates
(使用mapView.userLocation.location.coordinate.latitude
和mapView.userLocation.location.coordinate.longitude properties
)
,然後注入這些座標到
-(void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated
。
出於某種原因,這並沒有爲我工作。它將我帶到座標(0.0000,0.0000)。下面是我的代碼,如果你有機會檢查出來。謝謝您的幫助!
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
容易得多:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
不要忘記設置mapView.delegate! – DAS 2012-08-15 13:53:04
這是最好的解決方案。感謝你們。 – 2012-09-18 19:02:24
耶或我可以使用region.center.latitude = mapView.userLocation.location.coordinate.latitude;我認爲它會正常工作? – ludo 2010-02-01 12:15:30
哼,我不確定它是否有效,我會建議你創建一個本地CLLocationCoordinate2D並將它注入給定的選擇器中。您可以控制動畫參數,這也可以使您的應用看起來更好用動畫。 – yonel 2010-02-01 13:26:15
我真的不知道如何使用你給我的選擇器,但我會嘗試,如果你有任何鏈接,告訴我也會很好。謝謝 – ludo 2010-02-01 15:30:27