B4A Class Open Street Map viewer - GPS

Hi,

This b4Xlib contains a custom view (cvMap) which can display Open Street Map.


screenshot.png
View attachment 109081



The tiles are retrieved from the internet and cached in a database. You can add shapes and images on the map.

UI :
- Lat/lng Center of the map
- Zoom Level
- Compass Direction with rotation
- Scale
- Button Menu
- Grid
- Center
- GPS position and bearing

Event :
- ready
- Lat/lng changed
- Zoom Level Changed
- Compass Direction Changed
- Shape Clicked
- Map Clicked
- Center Lat/lng clicked
- Button Menu clicked
- Scale clicked
- Compass Clicked
- GPS Clicked

Tile Server
2 new properties :
This 2 properties are available in the designer or with setter/getter from the cvmap : userAgent, tileServer

Dependencies :
- Core
- SQL
- OKHttpUtils2
- XUI
- XUI views

Other files in the b4xlib :
- coMapUtilities : code module with Types, functions, helpers
- clTileManager : standard class module to load tile from database and/or internet and save them into the database
- clMapShapeCirgle : standard class to draw circle on the map
- clMapShapeLine : standard class to draw line on the map
- clMapShapePolygon : standard class to draw polygon on the map
- clMapShapeImage : standard class to draw image on the map
- layout cvmap.bal and cvmap.bjl
- images for the compass and gps



How to use it :
- Just add the cvMap custom view with the designer
- create sub to handle events if necessary
- set options (lat/lng, zoom.....)

B4A example and B4J example included



spsp
 

Attachments

  • Screenshot_2021-02-21-11-49-10-222_map.b4A.com.jpg
    Screenshot_2021-02-21-11-49-10-222_map.b4A.com.jpg
    258.3 KB · Views: 1,649
  • B4Xmap.zip
    23 KB · Views: 1,611
  • B4Xmap.b4xlib
    23.7 KB · Views: 522
Last edited:

irda

Member
Licensed User
Longtime User
Hi, great job.
There must be a possibility but I can't find it. Is it possible to change the symbol of the current position (looks like the on/off button) and reduce the size of the +/- buttons? Thank you.
1652873611590.png
 

spsp

Active Member
Licensed User
Longtime User
Hi, great job.
There must be a possibility but I can't find it. Is it possible to change the symbol of the current position (looks like the on/off button) and reduce the size of the +/- buttons? Thank you.
View attachment 129311
Hello,

Symbol for current position : change the image 'bearing.png'.
+/- buttons, change in the cvmap layout file.

spsp
 

TILogistic

Expert
Licensed User
Longtime User
I get this picture in B4A:
View attachment 132529
What happened?
B4J in the map is displayed normally.
see:
 

Sergey_New

Well-Known Member
Licensed User
Longtime User
see:
Thanks, I'll try.
P.S.
This advice helped, thanks!
 
Last edited:

Nkalampika

Active Member
Licensed User
Hi,

This b4Xlib contains a custom view (cvMap) which can display Open Street Map.


View attachment 109092View attachment 109081



The tiles are retrieved from the internet and cached in a database. You can add shapes and images on the map.

UI :
- Lat/lng Center of the map
- Zoom Level
- Compass Direction with rotation
- Scale
- Button Menu
- Grid
- Center
- GPS position and bearing

Event :
- ready
- Lat/lng changed
- Zoom Level Changed
- Compass Direction Changed
- Shape Clicked
- Map Clicked
- Center Lat/lng clicked
- Button Menu clicked
- Scale clicked
- Compass Clicked
- GPS Clicked

Tile Server
2 new properties :
This 2 properties are available in the designer or with setter/getter from the cvmap : userAgent, tileServer

Dependencies :
- Core
- SQL
- OKHttpUtils2
- XUI
- XUI views

Other files in the b4xlib :
- coMapUtilities : code module with Types, functions, helpers
- clTileManager : standard class module to load tile from database and/or internet and save them into the database
- clMapShapeCirgle : standard class to draw circle on the map
- clMapShapeLine : standard class to draw line on the map
- clMapShapePolygon : standard class to draw polygon on the map
- clMapShapeImage : standard class to draw image on the map
- layout cvmap.bal and cvmap.bjl
- images for the compass and gps



How to use it :
- Just add the cvMap custom view with the designer
- create sub to handle events if necessary
- set options (lat/lng, zoom.....)

B4A example and B4J example included



spsp
Hello
 

petr4ppc

Well-Known Member
Licensed User
Longtime User

spsp

Active Member
Licensed User
Longtime User
Dear friends, please for help,

I have read:


With b4A 11.20 and B4X map version 2.0 I cant see userAgent and tileServer parameters.
I am looking for them because I see blue lines as was wrote: https://www.b4x.com/android/forum/threads/open-street-map-viewer-gps.127827/post-901884

Please very much for help,
best regards
p4ppc

(on pictures are fcvpam parameters I see)

View attachment 137824View attachment 137825View attachment 137826View attachment 137827
Hi,

post #1, B4XMap.B4XLib updated with the methods userAgent and tileServer

spsp
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear spsp,

I maybe being stupid but I dont know what I am doing wrong, please for help.

I have downloaded B4XMap.B4XLib from post #1. I see, it is Version 2.

I declare:
B4X:
Private fcvMap As cvMap

in fcvMap I am trying to find userAgent and tileServer
because of words in post #1: "or with setter/getter from the cvmap : userAgent, tileServer"

Please, what I am doing wrong,
thank you very much,
best regards
p4ppc
 

spsp

Active Member
Licensed User
Longtime User
Dear spsp,

I maybe being stupid but I dont know what I am doing wrong, please for help.

I have downloaded B4XMap.B4XLib from post #1. I see, it is Version 2.

I declare:
B4X:
Private fcvMap As cvMap

in fcvMap I am trying to find userAgent and tileServer
because of words in post #1: "or with setter/getter from the cvmap : userAgent, tileServer"

Please, what I am doing wrong,
thank you very much,
best regards
p4ppc
Hi,
userAgent and tileServer are 2 getter/setter of cvMap, so add this 2 lines in the fcvmap_ready sub

userAgent and tileServer:
private Sub fcvmap_ready
    fcvMap.TileServer="https://a.tile.openstreetmap.org/"
    fcvMap.UserAgent="User-AgentMozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0"
    'set values
    fcvMap.Map=fMap
    'draw the map
    fcvMap.draw
End Sub

spsp
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Hi,
userAgent and tileServer are 2 getter/setter of cvMap, so add this 2 lines in the fcvmap_ready sub

userAgent and tileServer:
private Sub fcvmap_ready
    fcvMap.TileServer="https://a.tile.openstreetmap.org/"
    fcvMap.UserAgent="User-AgentMozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0"
    'set values
    fcvMap.Map=fMap
    'draw the map
    fcvMap.draw
End Sub

spsp
Dear spsp,

I have same situation:
1673126574417.png


And in libraries I have:
1673126679965.png


EDIT: SPSP thank you very much, everything is OK. I tried to reinstal library again and now is everything perfect. The new library is Version 2 as previous library. I dont know where I did mistake, but now is everything perfect. Thank you for your time, Best regards , p4ppc
 
Last edited:

mw71

Active Member
Licensed User
Longtime User
Hi,

i have add 2 marker and a Line, works fine.
Now i search a way to move a Maker (to an other Lat/Lon Position)

ps: i used the Libary as Class
 

aminoacid

Active Member
Licensed User
Longtime User
Hi,

This b4Xlib contains a custom view (cvMap) which can display Open Street Map.

Hi! Nice work. Thanks!
Is there some reason why the jSQL library is included in the example but never used?
 

Lakhtin_V

Active Member
Licensed User
Longtime User
Hi,

This b4Xlib contains a custom view (cvMap) which can display Open Street Map.


View attachment 109092View attachment 109081



The tiles are retrieved from the internet and cached in a database. You can add shapes and images on the map.

UI :
- Lat/lng Center of the map
- Zoom Level
- Compass Direction with rotation
- Scale
- Button Menu
- Grid
- Center
- GPS position and bearing

Event :
- ready
- Lat/lng changed
- Zoom Level Changed
- Compass Direction Changed
- Shape Clicked
- Map Clicked
- Center Lat/lng clicked
- Button Menu clicked
- Scale clicked
- Compass Clicked
- GPS Clicked

Tile Server
2 new properties :
This 2 properties are available in the designer or with setter/getter from the cvmap : userAgent, tileServer

Dependencies :
- Core
- SQL
- OKHttpUtils2
- XUI
- XUI views

Other files in the b4xlib :
- coMapUtilities : code module with Types, functions, helpers
- clTileManager : standard class module to load tile from database and/or internet and save them into the database
- clMapShapeCirgle : standard class to draw circle on the map
- clMapShapeLine : standard class to draw line on the map
- clMapShapePolygon : standard class to draw polygon on the map
- clMapShapeImage : standard class to draw image on the map
- layout cvmap.bal and cvmap.bjl
- images for the compass and gps



How to use it :
- Just add the cvMap custom view with the designer
- create sub to handle events if necessary
- set options (lat/lng, zoom.....)

B4A example and B4J example included



spsp
How should the code be redone so that the map is displayed based on a previously downloaded file with the OCM extension. I don't have internet access during the map rendering process and I want to use one locality OSM file that I downloaded earlier via export from mapsource main site
 

aminoacid

Active Member
Licensed User
Longtime User
How should the code be redone so that the map is displayed based on a previously downloaded file with the OCM extension. I don't have internet access during the map rendering process and I want to use one locality OSM file that I downloaded earlier via export from mapsource main site

I think the maps are being cached but I cannot figure out where in the code this happens. The jSQL Library is included in the project but I don't see anywhere it is used. Removing the library reference has no effect on the compilation so the maps are not being stored in an SQL DB for sure.

This is the reason why I posted my question (post #96) to @spsp
 

spsp

Active Member
Licensed User
Longtime User
I think the maps are being cached but I cannot figure out where in the code this happens. The jSQL Library is included in the project but I don't see anywhere it is used. Removing the library reference has no effect on the compilation so the maps are not being stored in an SQL DB for sure.

This is the reason why I posted my question (post #96) to @spsp
Hi,

The tiles are retrieved from internet and stored in a sqlite database.
The module clMapTieManager.bas does the job.
spsp
 
Top