标签:
该方法在百度地图demo的公交车搜索一类文件里;
参数为所有标注点连成的折线;该方法通过这些标注点可改变地图显示范围;展示最优的显示比例(在自己的项目中亲测)
//根据polyline设置地图范围
func mapViewFitPolyLine(polyline: BMKPolyline!) {
if polyline.pointCount < 1 {
return
}
let pt = polyline.points[0]
var ltX = pt.x
var rbX = pt.x
var ltY = pt.y
var rbY = pt.y
for i in 1..<polyline.pointCount {
let pt = polyline.points[Int(i)]
if pt.x < ltX {
ltX = pt.x
}
if pt.x > rbX {
rbX = pt.x
}
if pt.y > ltY {
ltY = pt.y
}
if pt.y < rbY {
rbY = pt.y
}
}
let rect = BMKMapRectMake(ltX, ltY, rbX - ltX, rbY - ltY)
mapView!.visibleMapRect = rect
mapView!.zoomLevel = mapView!.zoomLevel - 0.3
}
标签:
原文地址:http://www.cnblogs.com/hazhede/p/5486371.html