代码之家  ›  专栏  ›  技术社区  ›  Im Batman

对于给定坐标,MKpolyline未正确显示

  •  1
  • Im Batman  · 技术社区  · 7 年前

    var points: [CLLocationCoordinate2D] = []
    
    let locationDetails = myArray as! [Location]
    
    for each in locationDetails{
        print("Latitude \(each.latitude) - Longitude \(each.longitude)")
        points.append(CLLocationCoordinate2DMake(each.latitude, each.longitude))
    }
    
    let centerLocation : Location = myArray.anyObject() as! Location
    let centerPoint = CLLocationCoordinate2DMake(centerLocation.latitude, centerLocation.longitude);
    
    print("POINTS \(points)")
    
    let polyline = MKPolyline(coordinates: points, count: points.count)
    mapView.add(polyline)
    
    let region = MKCoordinateRegionMakeWithDistance(centerPoint, 5000.0, 7000.0)
    mapView.setRegion(region, animated: true)
    

    但我的折线越来越乱。请参阅随附的屏幕截图。首先我想到了坐标的问题。但是当我试着用那些长和长 this online tool 它给了我别针完美的线条。 print

    Tested coordinates MapSDK polyline

    协调

    6.8517432035942099,79.905121140256398
    6.8475310038839003,79.902849560677893
    6.8581436667655202,79.908119598477995
    6.8374054133955697,79.893569033667305
    6.8566833715949702,79.907449213862293
    6.8406604416732097,79.898999668732202
    6.83810886461925,79.892979702055399
    6.8542092852358296,79.906306928098104
    6.8402581522304899,79.895430151447599
    6.8368830112804098,79.894324662238304
    6.8440497480396596,79.900090321972897
    6.8493188219208703,79.902743613421805
    6.8484064936701703,79.902548063620799
    6.85723423027141,79.908170560449307
    6.8450230546359396,79.899919834062402
    6.84973481577528,79.903571158721903
    6.8459125422004998,79.899705760255401
    6.8551684683252603,79.906455958336494
    6.8414650205586502,79.901498481705701
    6.8405259121273101,79.899981692507794
    6.8513044109631798,79.904290326014106
    6.8373792317329203,79.895165984713401
    6.8372333821392299,79.895255911941504
    6.8466924363811001,79.900271203443296
    6.8506548972864199,79.903621031045802
    6.8390314607013396,79.892975427284696
    6.8469577236164803,79.901166977435295
    6.83748895475187,79.895160402688802
    6.8398749735270101,79.896293487474196
    6.8407466076378203,79.893662072792594
    6.8422778556187103,79.900998165905406
    6.8398627359483797,79.893336938768499
    6.8408240983326403,79.894646443501003
    6.8560738395963403,79.906751504242294
    6.8469752417941097,79.902100302353404
    6.8374541960720299,79.895048104300997
    6.8374381558016104,79.895128792781804
    6.8524381890956798,79.905752716660402
    6.8407501699466602,79.900907306074998
    6.8401687173236496,79.897176772430399
    6.8405627925012604,79.898056201711199
    6.8430614378366998,79.900337923392598
    6.8532910058338699,79.906087154597003
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   Nex Mishra    7 年前

    我使用MKDirection请求创建多段线

    MKDirections *directions = [[MKDirections alloc] initWithRequest:directionsRequest];
    [directions calculateDirectionsWithCompletionHandler:
     ^(MKDirectionsResponse *response, NSError *error) {
         if (error) {
             // Handle Error
         }
         else
         {
             //[self showRoute:response];
             for (MKRoute *route in response.routes)
             {
                 [self.mapView addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
              }
         }
    
        2
  •  0
  •   Im Batman    7 年前

    这是数据阵列的问题。因为我从coredata中获得了坐标,所以这些坐标不符合顺序。这就是为什么它没有一个接一个地画出完美的界限。当我对数组进行排序后,我得到了完美的结果。 locationDetails = locationDetails.sorted(by: { $0.id < $1.id })