Hi all!
I used the example GPSExampleV2_4. My target is to make a click on the map and place there Icon and remember its coordinates. Coordinates of longitude and latitude I get without problems from MapView. But I can not put my icon correctly on the in the place where I clicked. I can not get the correct translation longitude and latitude into screen coordinates x, y.
x = (Lng - MapCenter.Longitude)*MapScaleLng + MapViewer.Width / 2 - 2.5%y
y = (MapCenter.Latitude - Lat)*MapScaleLat + MapViewer.Height / 2 - 2.5%y
this lines not work right
I used the example GPSExampleV2_4. My target is to make a click on the map and place there Icon and remember its coordinates. Coordinates of longitude and latitude I get without problems from MapView. But I can not put my icon correctly on the in the place where I clicked. I can not get the correct translation longitude and latitude into screen coordinates x, y.
B4X:
Sub CalcMapScales
' MapScaleLat = 360 / Power(2, MapZoomLevel) / MapViewer.Height
' MapScaleLng = MapScaleLat * CosD(MapCenter.Latitude)
MapScaleLng = Power(2, MapZoomLevel) * TileSize / 360
MapScaleLat = MapScaleLng * CosD(MapCenter.Latitude)
Log("Calculates the map scales MapZoomLevel " & MapZoomLevel & " MapHeight " & MapViewer.Height )
Log("Calculates MapScale Lng " & MapScaleLng & " Lat " & MapScaleLat )
Log("Calculates MapCenter Lng " & MapCenter.Longitude & " Lat " & MapCenter.Latitude)
End Sub
Sub MapViewer_Click(LatStr As String, LngStr As String)
' Log("MouseDown event of the MapViewer WebView defined in MapDisp")
Private Lat As Double, Lng As Double, x As Float, y As Float, k As Float
MapDispTimer.Enabled = True
k=MapViewer.Width/256
Lat = LatStr
Lng = LngStr
x = (Lng - MapCenter.Longitude)*MapScaleLng + MapViewer.Width / 2 - 2.5%y
y = (MapCenter.Latitude - Lat)*MapScaleLat + MapViewer.Height / 2 - 2.5%y
' x = (Lng - MapCenter.Longitude) / MapScaleLng + MapViewer.Width / 2
' y = (MapCenter.Latitude - Lat) / MapScaleLat + MapViewer.Height / 2
' MapXCursor = (Lng - MapCenter.Longitude) / MapScaleLng + MapViewer.Width / 2
' MapYCursor = (MapCenter.Latitude - Lat) / MapScaleLat + MapViewer.Height / 2
If Img.IsInitialized=False Then
Log("Curent MapScaleLng " & MapScaleLng & " MapScaleLat " & MapScaleLat )
Log("Curent MapCenter Lng " & MapCenter.Longitude & " Lat " & MapCenter.Latitude)
Log("Curent MapWidth " & MapViewer.Width & " MapHeight " & MapViewer.Height)
Log("Curent Lng x" & Lng & " Lat y" & Lat & " x " & x & " y " & y)
If File.Exists(File.DirAssets,"z_help.png")=True Then
Img.Initialize(File.DirAssets,"z_help.png")
lblImgTarget.Initialize("None")
lblImgTarget.SetBackgroundImage(Img)
Activity.AddView(lblImgTarget, x, y, 5%y, 5%y)
End If
Else
Log("END MapScaleLng " & MapScaleLng & " MapScaleLat " & MapScaleLat )
Log("END MapCenter Lng " & MapCenter.Longitude & " Lat " & MapCenter.Latitude)
Log("END MapWidth " & MapViewer.Width & " MapHeight " & MapViewer.Height)
Log("END Lng x" & Lng & " Lat y" & Lat & " x " & x & " y " & y)
MapDispTimer.Enabled = True
lblImgTarget.Top=y
lblImgTarget.Left=x
lblImgTarget.Invalidate
End If
End Sub
x = (Lng - MapCenter.Longitude)*MapScaleLng + MapViewer.Width / 2 - 2.5%y
y = (MapCenter.Latitude - Lat)*MapScaleLat + MapViewer.Height / 2 - 2.5%y
this lines not work right