ThinkGeo.com    |     Documentation    |     Premium Support

Plotting GPS data with Google Map

 


I am using Map Suite 5 desktop edition with VS 2010. Here I am using GoogleMapsOverlay as background map and the map loaded successfully. I have GPS Lat Long stored in sql server 2005 database. Here I am picking all Lat Long from my database and putted into InmemeoryFeatureLayer. All InmemeoryFeatureLayer are putted into a GroupLayer. The projection of InmemeoryFeatureLayer set accordingly and all data shows on my google map on proper route.


Now the Problem is when I am trying to zoom In/Out either with Mouse Left button double click/ Right button double click, the maps zooming in In/Out mode, but the route plotted with InmemeoryFeatureLayer not alligning with google map properly. What is the reason for this beahaviour I am not clear about it. Please help


To Show Google Map I am using following code


WinformsMap1.MapUnit = GeographyUnit.Meter

CurrentGeographicalUnit = setGeographicalUnit(WinformsMap1.MapUnit)

Dim googleMapLayer As GoogleMapsOverlay = New GoogleMapsOverlay()

googleMapLayer.MapType = GoogleMapsMapType.RoadMap

WinformsMap1.Overlays.Add("googleOverlay", googleMapLayer)

WinformsMap1.Overlays.MoveToBottom(WinformsMap1.Overlays.IndexOf(googleMapLayer))

Application.DoEvents()

G_GoogleLayerSelected = True

mnuSetGoogleMap.Text = "Remove Google Map"

WinformsMap1.ZoomLevelSnapping = ZoomLevelSnappingMode.None

WinformsMap1.ZoomToScale(WinformsMap1.ZoomLevelSet.ZoomLevel10.Scale)


Dim centerLatLong As Vertex

Dim xLat As Double = 28.633048

Dim xLong As Double = 77.219639

centerLatLong = GetLatLongInMeter(xLat, xLong)

WinformsMap1.CenterAt(New PointShape(centerLatLong))


 


To show my GPS data I am using following code




cmd.Connection = SqlCon

cmd.CommandText = "Select * from GPSData where DeviceID='" & DeviceID & "' and RecDate>='" & RecDateFrom & "' and RecDate<='" & RecDateTo & "'"

daDriveData.SelectCommand = cmd

daDriveData.Fill(dsDriveData)

If dsDriveData.Tables(0).Rows.Count > 0 Then

    Dim pointLayer As InMemoryFeatureLayer = New InMemoryFeatureLayer()

    pointLayer.Name = "PLayer1"

    ExplorerHelper.SetStylebyWellKnownTypeForMemoryLayer(pointLayer)

    pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

    pointLayer.DrawingQuality = DrawingQuality.CanvasSettings

    Dim SiteLayer As GroupLayer = New GroupLayer

    SiteLayer.Name = "GRPLayer1"

    SiteLayer.Layers.Add("pointFeatureLayer", pointLayer)

    WinformsMap1.Overlays("layerOverlay").Lock.EnterWriteLock()

    Try

       DirectCast(WinformsMap1.Overlays("layerOverlay"), LayerOverlay).Layers.Add(SiteLayer.Name, SiteLayer)

    Finally

       WinformsMap1.Overlays("layerOverlay").Lock.ExitWriteLock()

    End Try

    pointLayer.Open()

    For i = 0 To dsDriveData.Tables(0).Columns.Count - 1

       pointLayer.Columns.Add(New FeatureSourceColumn("" &                     dsDriveData.Tables(0).Columns(i).ColumnName.ToString &             ""))

    Next

    pointLayer.Close()

    ReDim Preserve PointShapeForSite(dsDriveData.Tables(0).Rows.Count - 1)

    For i = 0 To dsDriveData.Tables(0).Rows.Count - 1

       If IsNumeric(dsDriveData.Tables(0).Rows(i)("LAT")) = True And                                            IsNumeric(dsDriveData.Tables(0).Rows(i)("LNG")) = True Then

         SiteLongitude = CType(dsDriveData.Tables(0).Rows(i)("LAT"), Double)

         SiteLatitude = CType(dsDriveData.Tables(0).Rows(i)("LNG"), Double)

         PointShapeForSite(i) = New PointShape(SiteLatitude, SiteLongitude)

         PointName = "P" & i.ToString

         PointShapeForSite(i).Id = "p" & i.ToString

         pointLayer.InternalFeatures.Add(PointName, New Feature(PointShapeForSite(i)))

         pointFeature = pointLayer.InternalFeatures(PointName)

         For y = 0 To dsDriveData.Tables(0).Columns.Count - 1

            pointFeature.ColumnValues.Add("" & dsDriveData.Tables(0).Columns(y).ColumnName & "",                              dsDriveData.Tables(0).Rows(i)("" & dsDriveData.Tables(0).Columns(y).ColumnName & ""))

         Next

       End If

    Next

    '----------------Set Projection

    Dim centerLatLong As Vertex

    centerLatLong = SetProjectionForInmemoryLayer(pointLayer)

    WinformsMap1.CenterAt(New PointShape(centerLatLong))

    WinformsMap1.Refresh()

    WinformsMap1.ZoomToScale(WinformsMap1.ZoomLevelSet.ZoomLevel10.Scale)

 End If


To Set Projection I have used following code


Public Function SetProjectionForInmemoryLayer(ByVal layer As InMemoryFeatureLayer) As Vertex

        Dim boundingBox As RectangleShape = Nothing

        Process.GetCurrentProcess().ProcessorAffinity = CType(1, System.IntPtr)

        layer.FeatureSource.Projection = Nothing

        If layer.HasBoundingBox Then

            If Not layer.IsOpen Then

                layer.Open()

            End If

            If boundingBox Is Nothing Then

                boundingBox = layer.GetBoundingBox()

            Else

                boundingBox.ExpandToInclude(layer.GetBoundingBox())

            End If

            layer.Close()

        End If

        Dim boxArea As String = boundingBox.ToString

        Dim bArea() As String = Split(boxArea, ",")

        Dim xLatCor As Double

        Dim yLongCor As Double

        If CDbl(bArea(0)) <> 0 Then

            xLatCor = CDbl(bArea(0))

            If xLatCor < 0 Then

                xLatCor = CDbl(bArea(2))

            End If

        Else

            xLatCor = CDbl(bArea(2))

        End If

        If CDbl(bArea(1)) <> 0 Then

            yLongCor = CDbl(bArea(1))

            If yLongCor < 0 Then

                yLongCor = CDbl(bArea(3))

            End If

        Else

            yLongCor = CDbl(bArea(3))

        End If

        Dim decimalDegreevalue As Vertex

        If Math.Abs(xLatCor) > -180 And Math.Abs(xLatCor) < 180 Then

            'This is decimal degree map

            If G_GoogleLayerSelected = True Then

                Dim proj4 As ManagedProj4Projection = New ManagedProj4Projection()

                'proj4.InternalProjectionParametersString = ManagedProj4Projection.GetWgs84ParametersString

                proj4.InternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString

                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()

                layer.FeatureSource.Projection = proj4


                proj4.Open()

                decimalDegreevalue = proj4.ConvertToExternalProjection(CDbl(bArea(0)), CDbl(bArea(3)))

                proj4.Close()

            Else

                decimalDegreevalue = New Vertex(CDbl(bArea(0)), CDbl(bArea(3)))

            End If

        Else

            'This is meter map

            Dim proj4 As ManagedProj4Projection = New ManagedProj4Projection

            proj4.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(32643)

            proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326)

            layer.FeatureSource.Projection = proj4


            proj4.Open()

            decimalDegreevalue = proj4.ConvertToInternalProjection(CDbl(bArea(0)), CDbl(bArea(3)))

            proj4.Close()

        End If

        layer.DrawingQuality = DrawingQuality.CanvasSettings

        Return decimalDegreevalue

    End Function

 



Hi Sanjay, 
  
 Could you please check your data or send it to us to see if it’s not accurate? Maybe the data is not correct. Also I noticed you mentioned you are using MapSuite 5, could you please use the 6.0 version to see the offset is still there? 
  
 Thanks, 
 Edgar

Thanks for reply,


Data is correct, because when I am using these data with TabFeatureLayer (with .TAB file), its working properly. The problem comes when I am using GoogleMapsOverlay. In this case also the first loading of data seems ok, and after the zoom in/out, its not on the position, where it should be as I shown in attached file. How I send data to you, as I have told earlier, the data is stored in sql server 2005 database.


The version I am using is 5.0.119.0. Since the service agreement is not continued, thats why I am using our last version


Thanks

Sanjay


 



Hi Sanjay,  
  
 Looks like you are using one of the Development Builds, Perhaps the easiest option would be for you to download the Map Suite Desktop Evaluation Edition 6.0 from the Free Trial Downloads section of this site. You could then reference these dlls as I do see there were some changes to the 5.5 version to resolve issues with the GoogleMapsOverlay not lining up correctly. However without a software assurance plan in place we cannot supply a set of Full Edition 5.5 dlls. If you would like to renew your software assurance please feel free to contact your sales representative.