【问题标题】:How to show a place-mark with specific angle information on Maps app (Apple Maps or Google Maps)?如何在地图应用程序(Apple Maps 或 Google Maps)上显示带有特定角度信息的地标?
【发布时间】:2018-11-28 06:56:17
【问题描述】:

我想在地图应用上显示枪击信息。枪声有两个主要属性:

  1. 位置 - 射击点
  2. 方向/角度 - 相对于指南针北

使用以下代码 sn-p,我可以打开带有特定地标的地图应用。

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];

是否可以将角度/方向信息与地标一起添加?基本上地标应该随着地图旋转,以便清楚地描绘出枪声的方向。

【问题讨论】:

    标签: ios objective-c gps maps mapkit


    【解决方案1】:
    • 您可以使用谷歌地图和标记的旋转属性来实现标记的旋转。
    • 虽然您需要 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
    

    【讨论】:

    • 我希望它由地图应用程序处理,而不是作为我应用程序中的子视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 2016-08-30
    • 2011-01-13
    • 2015-09-30
    • 1970-01-01
    相关资源
    最近更新 更多