2012-12-19 15 views
5

मैं सीखने की कोशिश कर रहा हूं कि आईओएस 6 में मानचित्र पर दो बिंदुओं को जोड़ने के लिए पॉलीलाइन का उपयोग कैसे करें। सबसे पहले, मैंने इस विषय पर हर ट्यूटोरियल पर पढ़ा है कि एक साधारण Google खोज बदल जाती है और पॉलिलाइन को एक कारण से काम नहीं मिल सकती है। मैंने जो भी ट्यूटोरियल देखा है वह हमेशा पॉलीलाइन को मानचित्र में जोड़ता है और पूरे लाइन में फिट करने के लिए मानचित्र के ज़ूम को समायोजित करता है। Ios6 में मैप में पॉलीलाइन बनाने और जोड़ने के बारे में मैं कैसे जाउंगा यदि मैं चाहता हूं कि नक्शा निरंतर दूरी पर ज़ूम इन रहें और केवल पॉलीलाइन का अंत दिखाएं यदि यह बड़ा दृश्य है तो वर्तमान दृश्य? उदाहरण के लिए कहते हैं कि मैं एक पॉलीलाइन कि एक मील लंबा था था और नक्शे के लिए एक constand distacne बराबर पर में ज़ूम इन किया रहने के लिए चाहता था:मैपकिट पॉलीलाइन कस्टम ज़ूम?

MKCoordinateRegion userRegion = MKCoordinateRegionMakeWithDistance(self.currentLocation.coordinate, 1000, 1000); 
    [self.mainMap setRegion:[self.mainMap regionThatFits:userRegion] animated:YES]; 

मैं यह कर के बारे में कैसे जाना होगा? कृपया पूर्ण कोड उदाहरण या नमूना प्रोजेक्ट प्रदान करें जो मैं डाउनलोड कर सकता हूं!

+0

आप जो चाहते हैं वह ज़ूम रखें जो आपका वर्तमान स्थान और आपकी पॉलीलाइन दृश्य दिखाता है? – james075

उत्तर

0

MKMapPoint * malloc/असाइन:

MKMapPoint *newPoints = malloc((sizeof (MKMapPoint) * nbPoints)); 
newPoints[index] = varMKMapPoint; 
free(newPoints); 

MKPolyline में प्रारंभ किया जाना चाहिए अपने की जरूरत:

MKPolyline *polyline = [MKPolyline polylineWithPoints:newPoints count:nbPoints]; 
[self.mapView addOverlay:polyline]; 

अपने MKPolyline प्रदर्शित करने के लिए, आप viewForOverlay उपयोग करने के लिए:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay 
{ 
    MKOverlayView* overlayView = [[MKOverlayView alloc] initWithOverlay:overlay];   
    if([overlay isKindOfClass:[MKPolyline class]]) { 
     MKPolylineView *backgroundView = [[MKPolylineView alloc] initWithPolyline:overlay]; 
     backgroundView.fillColor = [UIColor blackColor]; 
     backgroundView.strokeColor = backgroundView.fillColor; 
     backgroundView.lineWidth = 10; 
     backgroundView.lineCap = kCGLineCapSquare; 
     overlayView = backgroundView; 
    } 
    return overlayView; 
} 

इस विधि का उपयोग करने के लिए, आपको अपने अंक CLLocation में कनवर्ट करना होगा, यह एक MKCoordinateR लौटाएगा उदाहरण के लिए कि आप मानचित्र पर सेट करेंगे देखें:

- (MKCoordinateRegion)getCenterRegionFromPoints:(NSArray *)points 
{ 
    CLLocationCoordinate2D topLeftCoordinate; 
    topLeftCoordinate.latitude = -90; 
    topLeftCoordinate.longitude = 180; 
    CLLocationCoordinate2D bottomRightCoordinate; 
    bottomRightCoordinate.latitude = 90; 
    bottomRightCoordinate.longitude = -180; 
    for (CLLocation *location in points) { 
     topLeftCoordinate.longitude = fmin(topLeftCoordinate.longitude, location.coordinate.longitude); 
     topLeftCoordinate.latitude = fmax(topLeftCoordinate.latitude, location.coordinate.latitude); 
     bottomRightCoordinate.longitude = fmax(bottomRightCoordinate.longitude, location.coordinate.longitude); 
     bottomRightCoordinate.latitude = fmin(bottomRightCoordinate.latitude, location.coordinate.latitude); 
    } 
    MKCoordinateRegion region; 
    region.center.latitude = topLeftCoordinate.latitude - (topLeftCoordinate.latitude - bottomRightCoordinate.latitude) * 0.5; 
    region.center.longitude = topLeftCoordinate.longitude + (bottomRightCoordinate.longitude - topLeftCoordinate.longitude) * 0.5; 
    region.span.latitudeDelta = fabs(topLeftCoordinate.latitude - bottomRightCoordinate.latitude) * 1.2; //2 
    region.span.longitudeDelta = fabs(bottomRightCoordinate.longitude - topLeftCoordinate.longitude) * 1.2; //2 
// NSLog(@"zoom lvl : %f, %f", region.span.latitudeDelta, region.span.latitudeDelta); 
    return region; 
} 

आशा है कि इससे मदद मिलती है।

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