iOS MapKit:如何在覆盖旁边滑动并相应地获取数据
我想在我的iOS地图上沿着覆盖区滑动,这样我就可以获得任何给定点的数据 在草图中创建的示例: 如何处理这样的问题?如果你知道任何可以使用MapKit来容纳这些东西的豆荚和图书馆,我很乐意与你分享 您建议如何处理此类功能的实现过程 我是否应该专注于使用相关的触摸手势识别器在地图上创建自定义指针,并尝试使用某种回调更新括号中的数据 也许这个特性已经部分实现了,只是让这些部分协同工作的问题 我的代码用于查看带有覆盖的地图iOS MapKit:如何在覆盖旁边滑动并相应地获取数据,ios,swift,mapkit,Ios,Swift,Mapkit,我想在我的iOS地图上沿着覆盖区滑动,这样我就可以获得任何给定点的数据 在草图中创建的示例: 如何处理这样的问题?如果你知道任何可以使用MapKit来容纳这些东西的豆荚和图书馆,我很乐意与你分享 您建议如何处理此类功能的实现过程 我是否应该专注于使用相关的触摸手势识别器在地图上创建自定义指针,并尝试使用某种回调更新括号中的数据 也许这个特性已经部分实现了,只是让这些部分协同工作的问题 我的代码用于查看带有覆盖的地图 func mapRegion() -> MKCoordinateRe
func mapRegion() -> MKCoordinateRegion {
let initialLoc = self.locations[0]
var minLat = initialLoc.latitude
var minLng = initialLoc.longitude
var maxLat = minLat
var maxLng = minLng
let locations = self.locations
for location in locations {
minLat = min(minLat, location.latitude)
minLng = min(minLng, location.longitude)
maxLat = max(maxLat, location.latitude)
maxLng = max(maxLng, location.longitude)
}
return MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: (minLat + maxLat)/2,
longitude: (minLng + maxLng)/2),
span: MKCoordinateSpan(latitudeDelta: (maxLat - minLat)*1.1,
longitudeDelta: (maxLng - minLng)*1.1))
}
@objc(mapView:rendererForOverlay:) func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let polyline = overlay as! MulticolorPolylineSegment
let renderer = MKPolylineRenderer(polyline: polyline)
renderer.strokeColor = polyline.color
renderer.lineWidth = 3
return renderer
}
func polyline() -> MKPolyline {
var coords = [CLLocationCoordinate2D]()
let locations = self.locations
for location in locations {
coords.append(CLLocationCoordinate2D(latitude: location.latitude,
longitude: location.longitude))
print("dodalo")
}
return MKPolyline(coordinates: &coords, count: run.locations.count)
}
func loadMap() {
if run.locations.count > 0 {
mapView.isHidden = false
print(self.locations)
// Set the map bounds
mapView.region = mapRegion()
// Make the line(s!) on the map
let colorSegments = MulticolorPolylineSegment.colorSegments(forLocations: self.locations)
mapView.addOverlays(colorSegments)
} else {
// No locations were found!
mapView.isHidden = true
UIAlertView(title: "Error",
message: "Sorry, this run has no locations saved",
delegate:nil,
cancelButtonTitle: "OK").show()
}
}
PS.我知道这个问题可能会被认为是基于观点的,但我不知道有什么更好的地方可以问这个问题。请给我建议一个更好的地方,而不是向下投票,它的浏览量概率相等。与stackoverflow相比,StackExchange代码审查几乎没有被访问过