c# - 如何在Gmap.Net中显示车辆移动方向

标签 c# google-maps gps latitude-longitude gmap.net

我正在使用 Gmap.net API 进行小型车辆跟踪项目。该项目采用 Windows 窗体 C# 形式。我从设备获取信息,例如:纬度、经度、速度、航向以及其他一些信息。 航向信息的单位是度(0~359),如何用箭头标志显示车辆正在朝某个方向移动?

最佳答案

我知道这个帖子已经有将近一年的历史了,但这就是我创建一个根据船的方向旋转的船标记的方法。我还根据缩放级别以不同的方式绘制船。

抱歉没有评论!

Namespace GMap.NET.WindowsForms.Markers

Public Class GMapMarkerBoat
    Inherits GMapMarker
    Public Brush As Brush
    Public boatHeading As Double

    Public Sub New(ic As SEAS_DATA.ImageCluster, b As Brush)
        MyBase.New(ic.LatLong)
        boatHeading = ic.IMU_Heading

        Brush = b

        'Size of the marker
        Size = New Size(8, 8)

    End Sub

    Public Overrides Sub OnRender(g As Graphics)

        Dim newSize As Size
        Dim maxZoomLevel As Integer = SEAS_Forms.frmMain.myMap.MaxZoom

        Select Case SEAS_Forms.frmMain.myMap.Zoom
            Case maxZoomLevel
                newSize = New Size(Size.Width * 2, Size.Height * 2)
            Case maxZoomLevel - 1 To maxZoomLevel
                newSize = New Size(CInt(Size.Width * 1.5), CInt(Size.Height * 1.5))
            Case maxZoomLevel - 2 To maxZoomLevel - 1
                newSize = Size
            Case SEAS_Forms.frmMain.myMap.MinZoom To maxZoomLevel - 2
                newSize = New Size(CInt(Size.Width / 2), CInt(Size.Height / 2))
        End Select

        'boat
        Dim boat(4) As PointF

        boat(0).X = CSng(-newSize.Width / 2)
        boat(0).Y = CSng(-newSize.Height / 2)
        boat(1).X = (boat(0).X + newSize.Width)
        boat(1).Y = boat(0).Y
        boat(3).X = boat(0).X
        boat(3).Y = (boat(0).Y + newSize.Height)
        boat(2).X = boat(1).X
        boat(2).Y = boat(3).Y
        boat(4).X = CSng(boat(0).X - newSize.Width / 2)
        boat(4).Y = CSng(boat(0).Y + newSize.Width / 2)

        If SEAS_Forms.frmMain.myMap.Zoom > maxZoomLevel - 4 Then
            boat = TransformAndRotate(boatHeading, boat) 'simplified rotation and transformation matrix
        Else
            boat = TransformAndRotate(0, boat)
        End If

        'start drawing here
        Select Case SEAS_Forms.frmMain.myMap.Zoom
            Case maxZoomLevel - 3 To maxZoomLevel
                g.FillPolygon(Brush, boat)
            Case SEAS_Forms.frmMain.myMap.MinZoom To maxZoomLevel - 3
                Dim newRect As New RectangleF(boat(0).X, boat(0).Y, newSize.Width, newSize.Height)
                g.FillEllipse(Brush, newRect)
        End Select

    End Sub

    Private Function TransformAndRotate(heading As Double, points() As PointF) As PointF()

        Dim cosRot As Double = Math.Cos((heading + 90) * Math.PI / 180)
        Dim sinRot As Double = Math.Sin((heading + 90) * Math.PI / 180)

        For i = 0 To points.Length - 1
            Dim x As Single = points(i).X
            Dim y As Single = points(i).Y
            points(i).X = CSng((LocalPosition.X) + (x * cosRot - y * sinRot)) 'simplified rotation and transformation matrix
            points(i).Y = CSng((LocalPosition.Y) + (x * sinRot + y * cosRot))
        Next

        Return points
    End Function

End Class

End Namespace

我传入的自定义类对象(ic As ImageCluster)具有 PointLatLng 和标题的属性。

这是我添加标记的方法

'add the marker to the overlay
newOverlay.Markers.Add(New GMap.NET.WindowsForms.Markers.GMapMarkerBoat(ic, Brushes.Red))

关于c# - 如何在Gmap.Net中显示车辆移动方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39805187/

相关文章:

C# 嵌套类/结构可见性

fragment 中的 Android 谷歌地图

PHP exif_read_data 不再提取 GPS 位置

android - Ionic 2 和 Cordova 地理定位之间的集成

c# - 多个期望/断言来验证测试结果

c# - ASP.NET 检测 USB 驱动器

javascript - 如何单独显示信息框中的标记信息?

ios - 在 iOS 中实现基于位置的服务的最佳实践

c# - 使用 SecurityPermissionFlag.Execution 沙箱化的 AppDomain 有多安全?

iphone - 如何在谷歌地图 iOS 中找到当前位置?