2009-04-26 5 views
5

मैं आईफोन के लिए Route-Me लाइब्रेरी का उपयोग कर रहा हूं। मेरी समस्या यह है कि मैं उदाहरण के लिए मानचित्र पर पथ बनाना चाहता हूं।आईफोन में मानचित्र पर पथ खींचें

मैं डलास में हूं और मैं न्यू यॉर्क जाना चाहता हूं तो बस मैं इन दो स्थानों पर मार्कर डालूंगा और पथ दो मार्करों के बीच खींचा जाएगा।

क्या कोई भी शरीर मुझे सुझाव दे सकता है कि यह कैसे किया जा सकता है।

यदि रूटमे के बजाए कोई अन्य मानचित्र है तो यह भी ठीक है।

उत्तर

0

क्षमा करें, मैंने ऐसा कुछ नहीं देखा है - मैं केवल यह ध्यान दूंगा कि अगर लोग आपको वोट दे रहे हैं क्योंकि उन्हें लगता है कि आप नई एसडीके मानचित्रण सुविधाओं के बारे में बात कर रहे हैं, तो फिर से अपना प्रश्न पढ़ने के लिए जहां आप एक बात कर रहे हैं तृतीय पक्ष लाइब्रेरी (अभी भी संभवतः एक वैध आवश्यकता है क्योंकि आप आधिकारिक मानचित्र एसडीके के साथ बारी-बारी-बारी दिशा-निर्देश नहीं कर सकते हैं)।

4

रूट-मेरे पास इस उद्देश्य के लिए RMPath कक्षा है। क्या आपने इसके साथ खेला है? यदि हां, तो आपने क्या किया, क्या किया और क्या काम नहीं किया?

7

निम्नलिखित कोड 2 अंक के बीच पथ खींच जाएगा।

// Set map view center coordinate 
CLLocationCoordinate2D center; 
center.latitude = 47.582; 
center.longitude = -122.333; 
slideLocation = center; 
[mapView.contents moveToLatLong:center]; 
[mapView.contents setZoom:17.0f]; 

// Add 2 markers(start/end) and RMPath with 2 points 
RMMarker *newMarker; 
UIImage *startImage = [UIImage imageNamed:@"marker-blue.png"]; 
UIImage *finishImage = [UIImage imageNamed:@"marker-red.png"]; 
UIColor* routeColor = [[UIColor alloc] initWithRed:(27.0 /255) green:(88.0 /255) blue:(156.0 /255) alpha:0.75]; 
RMPath* routePath = [[RMPath alloc] initWithContents:mapView.contents]; 
[routePath setLineColor:routeColor]; 
[routePath setFillColor:routeColor]; 
[routePath setLineWidth:10.0f]; 
[routePath setDrawingMode:kCGPathStroke]; 
CLLocationCoordinate2D newLocation; 
newLocation.latitude = 47.580; 
newLocation.longitude = -122.333; 
[routePath addLineToLatLong:newLocation]; 
newLocation.latitude = 47.599; 
newLocation.longitude = -122.333; 
[routePath addLineToLatLong:newLocation]; 
[[mapView.contents overlay] addSublayer:routePath]; 

newLocation.latitude = 47.580; 
newLocation.longitude = -122.333; 
newMarker = [[RMMarker alloc] initWithUIImage:startImage anchorPoint:CGPointMake(0.5, 1.0)]; 
[mapView.contents.markerManager addMarker:newMarker AtLatLong:newLocation]; 
[newMarker release]; 
newMarker = nil; 

newLocation.latitude = 47.599; 
newLocation.longitude = -122.333; 
newMarker = [[RMMarker alloc] initWithUIImage:finishImage anchorPoint:CGPointMake(0.5, 1.0)]; 
[mapView.contents.markerManager addMarker:newMarker AtLatLong:newLocation]; 
[newMarker release]; 
newMarker = nil; 
3

मार्ग-Me कैसे, उदाहरण के लिए नक्शे पर एक पथ आकर्षित करने के लिए वास्तव में नहीं है, लेकिन करीब (आपके मामले में आप सब मार्ग अंक जोड़ने के लिए)।

उपयोग RMPath ओवरले परत पर एक बहुभुज बनाने के लिए

//polygonArray is a NSMutableArray of CLLocation 
- (RMPath*)addLayerForPolygon:(NSMutableArray*)polygonArray toMap:(RMMapView*)map { 
    RMPath* polygonPath = [[[RMPath alloc] initForMap:map] autorelease]; 
    [polygonPath setLineColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5]]; 
    [polygonPath setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5]]; 
    [polygonPath setLineWidth:1]; 

    BOOL firstPoint = YES; 
    for (CLLocation* loc in polygonArray) { 
     if (firstPoint) { 
      [polygonPath moveToLatLong:loc.coordinate]; 
      firstPoint = NO; 
     } else { 
      [polygonPath addLineToLatLong:loc.coordinate]; 
     } 
    } 

    [polygonPath closePath]; 

    polygonPath.zPosition = -2.0f; 

    NSMutableArray *sublayers = [[[[mapView contents] overlay] sublayers] mutableCopy]; 
    [sublayers insertObject:polygonPath atIndex:0]; 
    [[[mapView contents] overlay] setSublayers:sublayers]; 
    return polygonPath; 
} 

नोट:

नवीनतम RouteMe addLineToCoordinate हैं: (CLLocationCoordinate2D) addLineToLatLong के बजाय समन्वय।

यह नया है एक मार्ग-मुझ में

- (RMMapLayer *)mapView:(RMMapView *)aMapView layerForAnnotation:(RMAnnotation *)annotation 
{ 
    if ([annotation.annotationType isEqualToString:@"path"]) { 
     RMPath *testPath = [[[RMPath alloc] initWithView:aMapView] autorelease]; 
     [testPath setLineColor:[annotation.userInfo objectForKey:@"lineColor"]]; 
     [testPath setFillColor:[annotation.userInfo objectForKey:@"fillColor"]]; 
     [testPath setLineWidth:[[annotation.userInfo objectForKey:@"lineWidth"] floatValue]]; 

     CGPathDrawingMode drawingMode = kCGPathStroke; 
     if ([annotation.userInfo containsObject:@"pathDrawingMode"]) 
      drawingMode = [[annotation.userInfo objectForKey:@"pathDrawingMode"] intValue]; 
     [testPath setDrawingMode:drawingMode]; 

     if ([[annotation.userInfo objectForKey:@"closePath"] boolValue]) 
      [testPath closePath]; 

     for (CLLocation *location in [annotation.userInfo objectForKey:@"linePoints"]) 
     { 
      [testPath addLineToCoordinate:location.coordinate]; 
     } 

     return testPath; 
    } 
    if ([annotation.annotationType isEqualToString:@"marker"]) { 
     return [[[RMMarker alloc] initWithUIImage:annotation.annotationIcon anchorPoint:annotation.anchorPoint] autorelease]; 
    } 

    return nil; 
} 
उदाहरण में MapTestBed में पाया
संबंधित मुद्दे