百度地图一些api和功能
让地图根据标注点显示范围(swift)
该方法在百度地图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
}
//在计算出可视的矩形后,为了让标注点更优的显示,将地图比例放大0.3.
获取当前版本号:BMKGetMapApiVersion()