2010-02-01 21 views
5

I "m sử dụng MapKit trong ứng dụng của tôi và disaply vị trí người dùng vớiLấy UserLocation Phối hợp với MapKit


[mapview setShowUserLocation:YES]; 

tôi muốn thiết lập các region.center.latitude và region.center.longitude với tọa độ của userLocation, làm thế nào để làm điều đó

Trả lời

10

Dưới đây là câu trả lời của tôi, tôi cố gắng một cái gì đó như thế và làm việc của nó:


//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]; }
1

tôi nghĩ rằng đây trả lời câu hỏi của bạn: Returning Mapkit Userlocation Coordinates

(sử dụng mapView.userLocation.location.coordinate.latitudemapView.userLocation.location.coordinate.longitude properties)

01.235.

và sau đó tiêm những tọa độ vào

-(void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

sơ thẩm MKMapView của bạn.

+0

vâng hoặc tôi có thể sử dụng region.center.latitude = mapView.userLocation.location.coordinate.latitude; Tôi nghĩ nó sẽ hoạt động đúng không? – ludo

+0

Hum, tôi không chắc chắn nếu nó hoạt động, tôi sẽ khuyên bạn nên tạo một CLLocationCoordinate2D địa phương và tiêm nó trong bộ chọn nhất định. Bạn có thể kiểm soát thông số hoạt ảnh mà cũng có thể làm cho ứng dụng của bạn trông đẹp hơn với hoạt ảnh. – yonel

+0

Tôi thực sự không biết cách sử dụng công cụ chọn bạn đã cho tôi nhưng tôi sẽ thử, nếu bạn có bất kỳ liên kết nào để hiển thị cho tôi cũng sẽ tốt. thanks – ludo

2

Đối với một số lý do, điều này không làm việc cho tôi. Nó đưa tôi đến tọa độ (0.0000, 0.0000). Dưới đây là mã của tôi nếu bạn có cơ hội để kiểm tra nó. Cảm ơn đã giúp đỡ!

[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]; 
6

Dễ dàng hơn nhiều:

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500); 
[mapView setRegion:region animated:YES]; 
} 
+2

Đừng quên đặt mapView.delegate! – DAS

+0

Đây là giải pháp tốt nhất. Cảm ơn các bạn. –

Các vấn đề liên quan