2017-02-25 10 views
12

मैं आईओएस के लिए नवीनतम Google मानचित्र API का उपयोग करके पॉलीलाइन ड्राइंग कर रहा हूं। मैं पॉइंटलाइन पॉइंट का निर्माण कर रहा हूं लेकिन यह ठीक से प्रतिपादन नहीं कर रहा है क्योंकि जब मैं पॉलीलाइन गायब हो जाता हूं (शब्दशः शब्दों में नहीं) और जब मैं इसमें ज़ूम करता हूं तो बस रेखा दिखाता है।Google मानचित्र पॉलीलाइन पूरी तरह से प्रतिपादन नहीं कर रहा है

Zoomed in view यह जब

Zoomed out view रूप से ज़ूम इन कैसे पॉलीलाइन प्रकट होता है यह है कि यह कैसे प्रकट होता है जब

यहाँ से ज़ूम आउट पॉलीलाइन

RCPolyline *polyline = [[RCPolyline alloc] init]; 
[polyline drawPolylineFromPoint:self.selectedEmployee.location toPoint:location]; 

ड्राइंग के लिए मेरे समारोह है मैं ओवरराइड init: है है आरसीपीओलाइन के लिए इस तरह कुछ होना चाहिए

- (instancetype)init { 
self = [super init]; 
if (self) { 
    self.strokeWidth = 5.0f; 
    self.strokeColor = UIColor.redColor; 
    self.geodesic = YES; 
    self.map = [RCMapView sharedMapView]; 
} 
return self;} 

और drawPolylineFromPoint:toPoint: इस

- (void)drawPolylineFromPoint:(CLLocation *)pointX toPoint:(CLLocation *)pointY { 
     GMSMutablePath *path = [GMSMutablePath path]; 
     [path addCoordinate:pointX.coordinate]; 
     [path addCoordinate:pointY.coordinate]; 
     self.path = path;} 
+0

मुझे लगता है कि आपका पॉलीलाइन पथ डेटा बहुत अधिक है। – wf9a5m75

+0

@ wf9a5m75 और इससे संबंधित कैसे है? –

+0

पथ का चित्रण बिंदु स्मृति का उपयोग करता है। बहुत से बिंदुओं का अर्थ है आईओएस के लिए Google मानचित्र एसडीके बहुत सारी मेमोरी का उपयोग करता है। मुझे लगता है कि यही कारण है। अपने अंक कम करने के लिए, आप अपने पथ को एन्कोड कर सकते हैं। यहां देखें http://stackoverflow.com/questions/30393067/google-maps-ios-sdk-level-of-detail-polylines – wf9a5m75

उत्तर

4

मैं गड़बड़ पाया, मैं RCPolyline वर्ग के स्थानीय उदाहरण बना रही थी और उस से पॉलीलाइन के निर्माण के लिए विधि बुला रहा था क्या मैं चाहता था RCPolyline के लिए एक वैश्विक वस्तु है के लिए गया था करता है उदाहरण और RCPolyline वर्ग उदाहरण के लिए

कुछ इस तरह GMSPath अद्यतन:

- (instancetype)initWithMap:(GMSMapView *)mapView { 
    self = [super init]; 
    if (self) { 
     self.strokeWidth = 4.0f; 
     self.strokeColor = [UIColor redColor]; 
     self.geodesic = YES; 
     self.map = mapView; 
     self.mutablePath = [GMSMutablePath path]; 
    } 
     return self;} 

और अब मैं इस विधि को उसी उदाहरण से कॉल कर रहा हूं।

- (void)appendPolylineWithCoordinate:(CLLocation *)location { 
    [self.mutablePath addCoordinate:location.coordinate]; 
    self.path = self.mutablePath;} 

पुनश्च: RCPolylineGMSPolyline

0

के उपवर्ग इस कोड का प्रयास करें है।

- (void)fetchPolylineWithOrigin:(CLLocation *)origin destination:(CLLocation *)destination { 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lat longitude:longg zoom:12]; 
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView.myLocationEnabled = YES; 
    self.view = mapView; 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.map = mapView; 
    NSString *originString = [NSString stringWithFormat:@"%f,%f", origin.coordinate.latitude, origin.coordinate.longitude]; 
    NSString *destinationString = [NSString stringWithFormat:@"%f,%f", destination.coordinate.latitude, destination.coordinate.longitude]; 
    NSString *directionsAPI = @"https://maps.googleapis.com/maps/api/directions/json?"; 
    NSString *directionsUrlString = [NSString stringWithFormat:@"%@&origin=%@&destination=%@&mode=driving&key=%@&alternatives=true", directionsAPI, originString, destinationString,@"YOUR API KEY"]; 
    NSURL *directionsUrl = [NSURL URLWithString:directionsUrlString]; 
    NSURLSessionDataTask *fetchDirectionsTask = [[NSURLSession sharedSession] dataTaskWithURL:directionsUrl completionHandler: 
               ^(NSData *data, NSURLResponse *response, NSError *error) 
               { 
                NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
                if(error) 
                { 
                 return; 
                } 
                NSArray *routesArray = [json objectForKey:@"routes"]; 
                GMSPolyline *polyline = nil; 
                int i=1; 
                for (id route in routesArray) 
                { 
                 NSDictionary *routeDict = [route valueForKey:@"overview_polyline"]; 
                 NSString *points = [routeDict objectForKey:@"points"]; 
                 GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init]; 
                 GMSPath *path = [GMSPath pathFromEncodedPath:points]; 
                 polyline = [GMSPolyline polylineWithPath:path]; 
                 polyline.strokeWidth = 3; 
                 if(i==1) 
                 { 
                  polyline.strokeColor = [UIColor greenColor]; 

                 }else if(i==2) 
                 { 
                  polyline.strokeColor = [UIColor redColor]; 
                 }else{ 
                  polyline.strokeColor = [UIColor blueColor]; 
                 } 
                 i = i+1; 

                 bounds = [bounds includingCoordinate:marker.position]; 
                 polyline.map=mapView; 
                } 
               }]; 
    [fetchDirectionsTask resume]; 
} 
+0

मैं दो निर्देशांक के बीच मार्ग प्राप्त करने के लिए एपीआई का उपयोग नहीं कर रहा हूं, मैं स्थान डेटा रिकॉर्ड कर रहा हूं क्योंकि उपयोगकर्ता आगे बढ़ रहा है और इसे साजिश कर रहा है –

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