B4J Question Find screen X, Y, of Google Map

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I am trying to find the screen XY of a Google map. In B4A I use the GoogleMapExtras library functions:
B4X:
Projection1 = GoogleMapsExtras1.GetProjection(gmap)
ScreenPosition = Projection1.toScreenLocation(MarkerLocation)
    BTSX = ScreenPosition.X
    BTSY = ScreenPosition.Y

The only problem is that there is no JGoogleMapExtras.

As always, any help much appreciated.

Regard Roger
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code works and is based on the only method available:
B4X:
Sub gmap_Click (Point As LatLng)
   Dim xy() As Double = LatLonToXY(Point)
   Log($"x = $1.2{xy(0)}, y = $1.2{xy(1))}"$
End Sub

Public Sub LatLonToXY(ll As LatLng) As Double()
   Dim jo As JavaObject = gmap
   jo = jo.GetFieldJO("map").RunMethod("getProjection", Null)
   If jo = Null Then Return Array As Double(-1, -1)
   jo = jo.RunMethod("fromLatLngToPoint", Array(ll))
   Return Array As Double(jo.RunMethod("getX", Null), jo.RunMethod("getY", Null))
End Sub

I'm not sure how these values refer to the screen.
 
Upvote 0
Top