Android Question Example of how to load GPS Coordinates into OpenStreetmap

mcqueccu

Well-Known Member
Licensed User
Longtime User
I need a simple example of how to load GPS Coordinates, example 27.9881° N, 86.9250° E into the Openstreetmap.

I downloaded the library https://www.b4x.com/android/forum/threads/open-street-map-viewer-gps.127827/#content and tried the examples but I keep getting squares with Lines.

If someone used it and knows how to implement it easily, kindly help

1713113112280.png
 
Solution
just change the tile server.
j.Download($"https://mt1.google.com/vt/lyrs=r&x=${aX}&y=${aY}&z=${aZ}"$)
B4X:
public Sub getTileFromInternet(aZ As Int,aX As Int,aY As Int) As ResumableSub
    Dim j As HttpJob
    Dim bmp As B4XBitmap
    Try
        j.Initialize("", Me)
'        j.Download($"${fTileServer}${aZ}/${aX}/${aY}.png"$)
        j.Download($"https://mt1.google.com/vt/lyrs=r&x=${aX}&y=${aY}&z=${aZ}"$)
        j.GetRequest.SetHeader("User-Agent",fUserAgent)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Try
                bmp=j.GetBitmap
            Catch
                Log(LastException.Message & CRLF & j.getString)
            End Try
        End If
    Catch...

TILogistic

Expert
Licensed User
Longtime User
database: Offline
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Change: server and useragent
B4X:
    fcvMap.TileServer
    fcvMap.UserAgent

See;
B4X:
'Get Tile from internet openstreemap website
public Sub getTileFromInternet(aZ As Int,aX As Int,aY As Int) As ResumableSub
    Dim j As HttpJob
    Dim bmp As B4XBitmap
    Try
        j.Initialize("", Me)
        j.Download($"${fTileServer}${aZ}/${aX}/${aY}.png"$)
        j.GetRequest.SetHeader("User-Agent",fUserAgent)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Try
                bmp=j.GetBitmap
            Catch
                Log(LastException.Message & crlf & j.getString)
            End Try
        End If
    Catch
        Log(LastException.Message)
    End Try
    If j.IsInitialized Then
        j.Release
    End If
    Return bmp
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
just change the tile server.
j.Download($"https://mt1.google.com/vt/lyrs=r&x=${aX}&y=${aY}&z=${aZ}"$)
B4X:
public Sub getTileFromInternet(aZ As Int,aX As Int,aY As Int) As ResumableSub
    Dim j As HttpJob
    Dim bmp As B4XBitmap
    Try
        j.Initialize("", Me)
'        j.Download($"${fTileServer}${aZ}/${aX}/${aY}.png"$)
        j.Download($"https://mt1.google.com/vt/lyrs=r&x=${aX}&y=${aY}&z=${aZ}"$)
        j.GetRequest.SetHeader("User-Agent",fUserAgent)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Try
                bmp=j.GetBitmap
            Catch
                Log(LastException.Message & CRLF & j.getString)
            End Try
        End If
    Catch
        Log(LastException.Message)
    End Try
    If j.IsInitialized Then
        j.Release
    End If
    Return bmp
End Sub
 
Upvote 0
Solution

mcqueccu

Well-Known Member
Licensed User
Longtime User
Thank you @TILogistic but I am a bit confused. with the code you posted which returns B4XBitmap from google Tile server,
does it mean that
1. dont need the openstreetmap Library again
2. How to I display the result from the getTilefromInternet, Do i add imageview?


The example project is just too much, Shapes, polygons etc. I just need a simple example to load just a coodinate
B4X:
Dim shapes As List
    shapes.Initialize
    shapes.Add(coMapUtilities.instanceShapeCircle(fcvMap,coMapUtilities.initShapeCircle(coMapUtilities.initLatLng(51.5073509,-0.1277583),10dip,fxui.Color_ARGB(128,255,0,255),True,1dip,"London")))
    shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(51.5073509,-0.1277583),coMapUtilities.initLatLng(48.856614,2.3522219),fxui.Color_ARGB(128,255,0,255),1dip,"London to Paris")))
    shapes.Add(coMapUtilities.instanceShapeCircle(fcvMap,coMapUtilities.initShapeCircle(coMapUtilities.initLatLng(48.856614,2.3522219),15dip,fxui.Color_ARGB(128,0,255,255),True,1dip,"Paris")))
    shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(48.856614,2.3522219),coMapUtilities.initLatLng(31.630000,-8.008889),fxui.Color_ARGB(128,255,0,255),1dip,"Paris to Marrakech")))
    shapes.Add(coMapUtilities.instanceShapeCircle(fcvMap,coMapUtilities.initShapeCircle(coMapUtilities.initLatLng(31.630000,-8.008889),7dip,fxui.Color_ARGB(128,255,255,0),True,1dip,"Marrakech")))
    shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(31.630000,-8.008889),coMapUtilities.initLatLng(14.7645042,-17.3660286),fxui.Color_ARGB(128,255,0,255),1dip,"Marrakech to Dakar")))
    shapes.Add(coMapUtilities.instanceShapeCircle(fcvMap,coMapUtilities.initShapeCircle(coMapUtilities.initLatLng(14.7645042,-17.3660286),20dip,fxui.Color_ARGB(128,0,255,0),True,1dip,"Dakar")))

    Dim polygonPoints As List
    polygonPoints.Initialize
    polygonPoints.add(coMapUtilities.initLatLng(43.09296067711627,5.855712890625))
    polygonPoints.add(coMapUtilities.initLatLng(43.54456658436355,10.30517578125))
    polygonPoints.add(coMapUtilities.initLatLng(47.394630761906456,8.52813720703125))
    shapes.Add(coMapUtilities.instanceShapePolygon(fcvMap,coMapUtilities.initShapePolygon(polygonPoints,fxui.Color_ARGB(128,128,128,128),True,1dip,"Polygon Toulon Livorno, Zurich")))
        
    shapes.Add(coMapUtilities.instanceShapeImage(fcvMap,coMapUtilities.initShapeImage(coMapUtilities.initLatLng(43.296482,5.36978),fxui.LoadBitmapResize(File.DirAssets,"marker.png",25dip,33dip,True),0,"Marseille")))
    
    'init fmap with lat/lng, direction, zoom level, options and some shapes
    fMap=coMapUtilities.initMap(coMapUtilities.initLatLng(48,2),5,0,False,True,True,True,False,True,True,True,True,True, _
                                shapes, _
                                True,False,coMapUtilities.initGPS(coMapUtilities.initLatLng(0,0),0))
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
One way would be like this, the other is the following.
I should also comment that I have changed this class to make it more friendly and assimilate it to Google Maps.

Yes, my answers are just what I see in this version of the class.
B4X:
    Dim shapes As List
    shapes.Initialize
    fMap=coMapUtilities.initMap(coMapUtilities.initLatLng(27.9881,86.9250),5,0,False,True,True,True,False,True,True,True,True,True, _
                                shapes, _
                                True,False,coMapUtilities.initGPS(coMapUtilities.initLatLng(0,0),0))

other
B4X:
'    fcvMap.CenterLatLng=coMapUtilities.initLatLng(27.9881,86.9250)
'    fcvMap.draw

1713128933096.png
 
Upvote 0
Top