// 1.OC的经纬度画线代码
CLLocationCoordinate2D coords[5] = {0};
coords[0] = CLLocationCoordinate2DMake(31.174805, 121.408186);
coords[1] = CLLocationCoordinate2DMake(31.172792, 121.408577);
coords[2] = CLLocationCoordinate2DMake(31.172575, 121.408623);
coords[3] = CLLocationCoordinate2DMake(31.171408, 121.407910);
coords[4] = CLLocationCoordinate2DMake(31.170963, 121.405790);
BMKPolyline *polyline = [BMKPolyline polylineWithCoordinates:coords count:5];
[_mapView addOverlay:polyline];
[_mapView setCenterCoordinate:coords[0]];
// 2. swift经纬度画线代码
var coords = [CLLocationCoordinate2D]()
coords.append(CLLocationCoordinate2D(latitude: 31.174805 , longitude: 121.408186))
coords.append(CLLocationCoordinate2D(latitude: 31.172792, longitude: 121.408577))
coords.append(CLLocationCoordinate2D(latitude: 31.172575, longitude: 121.408623))
coords.append(CLLocationCoordinate2D(latitude: 31.171408, longitude: 121.407910))
coords.append(CLLocationCoordinate2D(latitude: 31.170963, longitude: 121.405790))
let polyline = BMKPolyline(coordinates: &coords, count: UInt(coords.count))
self.mapView.add(polyline)
self.mapView.setCenter(coords[0], animated: true)
// 3. 显示鲜果对比
![WX20210512-140446@2x.png](https://upload-images.jianshu.io/upload_images/1434489-d6636dbb1065afb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
// 4. 解决方法
将swift的纬度减0.006, 经度减去0.0065
var coords = [CLLocationCoordinate2D]()
coords.append(CLLocationCoordinate2D(latitude: 31.174805 - 0.006, longitude: 121.408186 - 0.0065))
coords.append(CLLocationCoordinate2D(latitude: 31.172792 - 0.006, longitude: 121.408577 - 0.0065))
coords.append(CLLocationCoordinate2D(latitude: 31.172575 - 0.006, longitude: 121.408623 - 0.0065))
coords.append(CLLocationCoordinate2D(latitude: 31.171408 - 0.006, longitude: 121.407910 - 0.0065))
coords.append(CLLocationCoordinate2D(latitude: 31.170963 - 0.006, longitude: 121.405790 - 0.0065))
swift 百度地图Api定位不准确问题
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...