2010-02-01 14 views
5

साथ समन्वय मैं "अपने आवेदन में MapKit का उपयोग कर रहा हूँ और साथपुनः प्राप्त UserLocation MapKit


[mapview setShowUserLocation:YES]; 

मैं region.center.latitude और के समन्वय के साथ region.center.longitude सेट करना चाहते हैं उपयोगकर्ता स्थान disaply userLocation, इसे कैसे करना

उत्तर

10

यहाँ मेरी जवाब है मुझे लगता है कि और उसके काम करने की तरह कुछ की कोशिश:


//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

मुझे लगता है कि यह आपके सवाल का जवाब: Returning Mapkit Userlocation Coordinates

(का उपयोग करता mapView.userLocation.location.coordinate.latitude और mapView.userLocation.location.coordinate.longitude properties)

01,235,

और फिर

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

अपने MKMapView उदाहरण के

में उन निर्देशांक इंजेक्षन।

+0

हाँ या मैं region.center.latitude = mapView.userLocation.location.coordinate.latitude उपयोग कर सकते हैं; मुझे लगता है कि यह सही काम करेगा? – ludo

+0

हम, मुझे यकीन नहीं है कि यह काम करता है, मैं आपको स्थानीय CLLocationCoordinate2D बनाने और दिए गए चयनकर्ता में इंजेक्ट करने की सलाह दूंगा। आपको एनीमेशन पैरामीटर पर नियंत्रण मिलता है जो आपके ऐप को एनीमेशन के साथ अच्छी तरह से दिख सकता है। – yonel

+0

मुझे वास्तव में पता नहीं है कि आपने मुझे जो चयनकर्ता चुना है उसका उपयोग कैसे करें, लेकिन अगर आप मुझे दिखाने के लिए कोई लिंक रखते हैं तो मैं भी कोशिश करूंगा। धन्यवाद – ludo

2

किसी कारण से यह मेरे लिए काम नहीं किया। यह मुझे निर्देशांक (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]; 
6

बहुत आसान:

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

के बजाय @ "% f" करें mapView.delegate को सेट करना न भूलें! – DAS

+0

यह सबसे अच्छा समाधान है। आप लोगों को धन्यवाद। –

संबंधित मुद्दे