我想在 map 应用程序上显示枪声信息。枪声有两个主要属性:
- location - 射击点
- 方向/角度 - 相对于罗盘北
使用以下代码片段,我可以打开带有特定地标的 map 应用。
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(gps_lat.doubleValue, gps_long.doubleValue);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:self.pUnit.unitLabel];
[mapItem openInMapsWithLaunchOptions:nil];
是否可以添加角度/方向信息以及地点标记?基本上,地标应该随 map 旋转,以便清楚地描绘出枪声的方向。
最佳答案
- 您可以使用谷歌地图和标记的旋转属性实现标记的旋转。
尽管您需要 obj-c 代码,但我的 swift 代码将有助于您理解我的意思。
用您的图片替换 MARKER_IMAGE_NAME
1) 设置谷歌地图
let camera = GMSCameraPosition.camera(withLatitude: firstPoint.latitude,
longitude: firstPoint.longitude, zoom: 14)
let navHeight = (self.navigationController?.navigationBar.frame.size.height)! + 20
let frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height - navHeight)
let GMapView = GMSMapView.map(withFrame: frame, camera: camera)
self.view.addSubview(GMapView)
2) 准备标记
let bearing:Double = 90
var marker = GMSMarker()
marker.icon = UIImage(named: MARKER_IMAGE_NAME)
marker.appearAnimation = GMSMarkerAnimation.pop
3) 应用旋转
marker.rotation = bearing
4) 添加标记到谷歌地图
marker.map = GMapView
关于ios - 如何在 map 应用程序(苹果 map 或谷歌地图)上显示带有特定角度信息的地标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53513779/