2010-06-12 15 views
8

पर मैं कंपास/हेडिंग कैसे दिखा सकता हूं, आप उस आइकन पर क्लिक कर सकते हैं जो आमतौर पर आपकी स्थिति को दो बार दिखाता है और ब्लू डॉट लाभ हेडलैम्प से बीम की तरह दिखता है, मूल रूप से दिखा रहा है आप जिस दिशा में नक्शे पर सामना कर रहे हैं और तदनुसार छवि को घूर्णन कर रहे हैं।"मैप्स" ऐप में आईफोन 3 जीएस पर मैपकिट मैप्यूव

क्या यह विकल्प MapKit MapView का उपयोग कर उपलब्ध है?

मैं पता है कि मैं की तरह

- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading { 

// सटीकता मान्य है, तो प्रक्रिया घटना कुछ के साथ मेरी शीर्षक मिल सकती है।

if (newHeading.headingAccuracy > 0) { 

    CLLocationDirection theHeading = newHeading.magneticHeading; 
    ... 
} 

}

लेकिन मैं कैसे MapKit में है कि अच्छा हेडलैम्प असर पाने के लिए और वहाँ किसी भी प्रलेखन होना प्रतीत नहीं होता है पता नहीं है।

कोई विचार?

+0

यह एक अच्छा सवाल आईडी भी जवाब – si28719e

+0

मुझे लगता है कि जानना चाहता है जवाब यह है कि यह MapKit का उपयोग करके नहीं किया जा सकता है। मुझे आश्चर्य है कि जियोकैचिंग जैसे ऐप्स यह कैसे करते हैं? या, बल्कि, यदि यह आपके स्वयं के मानचित्र दृश्य को घुमाने में बहुत काम है। – PEZ

+0

self.mapView.userTrackingMode = RMUserTrackingModeFollowWithHeading का उपयोग करके किया जा सकता है; – ScarletWitch

उत्तर

2

मैं एक विधि के बारे में सोच सकता हूं, हालांकि मैंने लागू नहीं किया है लेकिन आप थोड़ा सा मदद कर सकते हैं।

  1. सबसे पहले आपको अपनी पसंद के सूचक के साथ एक छवि की आवश्यकता है, यह सूचक 9 0 डिग्री से ऊपर इंगित करना चाहिए।
  2. अब अपने मानचित्रकिट में वर्तमान स्थान मार्कर से बाहर है।
  3. अपने didUpdateHeading में दिशा के कोण की गणना करने के लिए x और y मानों का उपयोग करें।
  4. पॉइंटर
  5. की छवि को घुमाने के लिए इस कोण का उपयोग करें इस घुमावदार छवि को अपने मानचित्र में एनोटेशन पिन के रूप में उपयोग करें।
  6. आपको पॉइंटर की स्थिति को अक्सर अपडेट करने की आवश्यकता होगी।

उपर्युक्त दृष्टिकोण के लिए कृपया अपने सुझाव/परिवर्तन पोस्ट करें।

धन्यवाद

+0

आई मैप्स "पॉइंटर" घुमाया नहीं गया है, लेकिन नक्शा स्वयं ही, पॉइंटर हमेशा आपके डिवाइस के शीर्ष पर एक ही बिंदु पर रहता है। समस्या यह है कि एनोटेशन की स्थिति को कब अपडेट किया जाए। – myell0w

4

मैं एक समाधान मिला:

मैं

[mapView setTransform:CGAffineTransformMakeRotation(heading.magneticHeading * M_PI/-180.0)]; 

के साथ उपलब्ध शीर्षक-जानकारी का उपयोग कर मानचित्र को घुमाने इसलिए "किरण" हमेशा डिवाइस के शीर्ष की ओर इशारा करता। मैं अब सिर्फ नक्शे के शीर्ष पर एक imageView प्रदर्शित करने और बदलने के लिए यह स्थिति है locationManager में: didUpdateToLocation: fromLocation:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
     // scroll to new location 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 2000, 2000); 
    [self.mapView setRegion:region animated:YES]; 

     // set position of "beam" to position of blue dot 
    self.headingAngleView.center = [self.mapView convertCoordinate:newLocation.coordinate toPointToView:self.view]; 
     // slightly adjust position of beam 
    self.headingAngleView.frameTop -= self.headingAngleView.frameHeight/2 + 8; 
} 

जिससे frameTop और frameHeight frame.origin.y और frame.size.height के लिए शॉर्टकट हैं। यह आदर्श नहीं है और कभी-कभी डॉट में थोड़ी कमी होती है जब डॉट इसकी स्थिति बदलता है, लेकिन मैं समाधान बी/सी के साथ खुश हूं।

जो करता है मेरी OpenSource ढांचे MTLocation पर एक नज़र डालें यह सब (और आप के लिए अन्य शांत मानचित्र से संबंधित सामान का एक बहुत):

3

अन्य उत्तर के घूर्णन तर्क अच्छे हैं, हालांकि स्थान प्रबंधक प्रतिनिधि विधियों पर भरोसा न करने का परिणाम अच्छा समाधान नहीं होगा। "बीम" छवि शायद ही कभी नीली बिंदु के समान स्थान पर होगी और बहुत सारी उछाल जाएगी।

सबसे अच्छा समाधान ब्लू डॉट व्यू का संदर्भ प्राप्त करना है, और "बीम" छवि को इसके सबव्यूव के रूप में जोड़ें। मैं एक बीम छवि के साथ गया जो एक वर्ग था, जिसमें बीम ऊपर और पारिवारिकता थी। छवि के केंद्र में नीले बिंदु की कल्पना कीजिए।


// An MKMapViewDelegate method. Use this to get a reference to the blue dot annotation view as soon as it gets added 
- (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views { 

    for (MKAnnotationView *annotationView in views) { 

     // Get the user location view, check for all of your custom annotation view classes here 
     if (![annotationView isKindOfClass:[MKPinAnnotationView class]]) 
     { 
      self.userLocationAnnotationView = annotationView; 
      gotUsersLocationView = YES; 
     } 
    } 
} 


// Adds the 'viewPortView' to the annotation view. Assumes we have a reference to the annotation view. Call this before you start listening to for heading events. 
- (void)addViewportToUserLocationAnnotationView { 
    TTDASSERT(self.userLocationAnnotationView != nil); 
    if (self.userLocationAnnotationView == nil) { 
     // No reference to the view, can't do anything 
     return; 
    } 

    if (self.viewPortView == nil) { 
     self.viewPortView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map_viewport.png"]] autorelease]; 
    } 

    [self.userLocationAnnotationView addSubview:self.viewPortView]; 
    [self.userLocationAnnotationView sendSubviewToBack:self.viewPortView]; 

    self.viewPortView.frame = CGRectMake((-1 * self.viewPortView.frame.size.width/2) + self.userLocationAnnotationView.frame.size.width/2, 
             (-1 * self.viewPortView.frame.size.height/2) + self.userLocationAnnotationView.frame.size.height/2, 
             self.viewPortView.frame.size.width, 
             self.viewPortView.frame.size.height); 
} 
+0

क्या यह कोड आपके लिए काम कर रहा है? मैंने कोशिश की लेकिन उपयोगकर्ता स्थान नोटेशन रीमियन अपरिवर्तित देखें। – chatur

+0

आप addViewportToUserLocationAnnotationView विधि कहां कॉल करते हैं? – chatur

+0

अपडेट: didAddAnnotationViews को डिवाइस पर मेरे लिए नहीं बुलाया जा रहा है लेकिन सिम्युलेटर पर कॉल किया जाता है और आपका समाधान सिम्युलेटर पर पूरी तरह से काम करता है। क्या आपको कोई विचार है क्यों? – chatur

3

उपयोगकर्ता ट्रैकिंग मोड जोड़ना भी मदद करता है। मैं जानता हूँ कि मैं देर से कर रहा हूँ, लेकिन शायद मेरे जैसे अन्य डेवलपर्स के लिए एक मदद :)

self.mapView.userTrackingMode = RMUserTrackingModeFollowWithHeading; 
1

स्विफ्ट 3 कार्यान्वयन

mapView.userTrackingMode = MKUserTrackingMode.followWithHeading 
संबंधित मुद्दे