gpt4 book ai didi

ios - MKpolyline 无法正确显示给定坐标

转载 作者:行者123 更新时间:2023-11-28 08:03:20 27 4
gpt4 key购买 nike

我正在尝试使用以下代码绘制 MKpolyline。

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

最佳答案

我已经使用 MKDirection Request 创建折线

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];
}
}

关于ios - MKpolyline 无法正确显示给定坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45931668/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com