B4A Class Open Street Map viewer - GPS

Indy

Active Member
Licensed User
Longtime User

I'd like to try this version but, in an Android project not B4XPages. Can this be adapted for Android as is or do I need to change things?

Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
I'd like to try this version but, in an Android project not B4XPages. Can this be adapted for Android as is or do I need to change things?

Thanks
In the first post you find the b4a version not b4xpages.
 

TILogistic

Expert
Licensed User
Longtime User
i get error ResponseError. Reason: , Response: Access denied.

View attachment 109729



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($"https://a.tile.openstreetmap.org/${aZ}/${aX}/${aY}.png"$)
        j.GetRequest.SetHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Try
                bmp=j.GetBitmap
            Catch
                Log(LastException.Message)
            End Try
        End If
    Catch
        Log(LastException.Message)
    End Try
    If j.IsInitialized Then
        j.Release
    End If
    Return bmp
End Sub

Change tile server??
 

TILogistic

Expert
Licensed User
Longtime User
changing user agent works fine

j.GetRequest.SetHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
' j.GetRequest.SetHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0")
 

Star-Dust

Expert
Licensed User
Longtime User

Carlos marin

Active Member
Licensed User
Longtime User

Thanks for answering, I can't find this sub in the example, I don't know where to put it or where to call it, I don't get exactly where this error comes from
 

spsp

Active Member
Licensed User
Longtime User
Thanks for answering, I can't find this sub in the example, I don't know where to put it or where to call it, I don't get exactly where this error comes from
Hi,

The user-agent is in the file clMapTileManager.bas line 69 in the b4Xmap.b4Xlib (which is a zip file)



I don't know why it is OK in the B4A example and not in the B4J example.
 

spsp

Active Member
Licensed User
Longtime User
I'd like to try this version but, in an Android project not B4XPages. Can this be adapted for Android as is or do I need to change things?

Thanks

Hi,

an minimalist B4A example is attached in this post
 

Attachments

  • B4AOnlyMap.zip
    3.3 KB · Views: 435

TILogistic

Expert
Licensed User
Longtime User
Hi,

The user-agent is in the file clMapTileManager.bas line 69 in the b4Xmap.b4Xlib (which is a zip file)

View attachment 109806

I don't know why it is OK in the B4A example and not in the B4J example.
Read User-Agent;

 

Indy

Active Member
Licensed User
Longtime User
Hi,

an minimalist B4A example is attached in this post
Hi

Thank you for taking the time to put together a minimal project for me, really appreciate it. Unfortunately, when I run this I get a
B4X:
ResponseError. Reason: , Response: Access denied.

I don't know what's raising that error. Is there something I need to do? I don't appear to get any permission prompt, which looking at your B4XPages version you had.

Thanks
 

spsp

Active Member
Licensed User
Longtime User

Hi,

The permission is only for GPS, I don't use it in the minimal example.

Download again in the first post the B4XMap.b4Xlib. I've modified the user-agent. It should be OK

spsp
 

Indy

Active Member
Licensed User
Longtime User
Hi,

The permission is only for GPS, I don't use it in the minimal example.

Download again in the first post the B4XMap.b4Xlib. I've modified the user-agent. It should be OK

spsp

Just downloaded the lib again and retried the app - Worked perfectly! Thank you for your help. I should now be in a good position to convert my current app to use OSM instead of Google Maps.

Thanks again.
 

TILogistic

Expert
Licensed User
Longtime User
You could add the option to change the tile server (ServerTile) and user agent (UserAgent) by parameters.

Sample:
j.Download($"${ServerTile}${aZ}/${aX}/${aY}.png"$)

j.GetRequest.SetHeader("User-Agent",$"{UserAgent}"$)


to comply with the restrictions of tile servers.

User Agent: Email or App Name or Package Name.
Server Tile: use one the lista server or other personal : https://wiki.openstreetmap.org/wiki/Tile_servers
 

spsp

Active Member
Licensed User
Longtime User

Hi,

properties userAgent and tileServer added, see post #1

Thank you for your suggestion

spsp
 

Indy

Active Member
Licensed User
Longtime User
Hi,

Is there a way of reading back the current GPS position? I tried to see if there was a way of using the GPS_LocationChanged (aLocation As Location) event but that doesn't seem to do anything.

B4X:
Log(aLocation.Latitude)

I'm looking at incorporating the ability to be able to freely move the map (as it does now) and then click a button to put the map back to where I am now (current GPS pos).

Thanks
 

spsp

Active Member
Licensed User
Longtime User


Hi,

In cvMap , when the property followGPS is set to true, the map is centered and oriented according the GPS. when this property is set to false, you can move the map.

You can set to false/true this property with a button
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…