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,718
  • B4Xmap.zip
    23 KB · Views: 1,692
  • B4Xmap.b4xlib
    23.7 KB · Views: 601
Last edited:

aminoacid

Active Member
Licensed User
Longtime User
Hi,

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

Thanks for the reply. However, I'm looking at the B4J version of your B4XMap example and don't see this module anywhere. Am I missing something?
 

aminoacid

Active Member
Licensed User
Longtime User
Is there any way to enable the mouse scroll-wheel to zoom in and out, rather than have to use the + or - buttons?

Also, how do you get a Balloon callout when you click a marker... like in GoogleMaps ?

1693408523902.png


Thanks!
 
Last edited:

spsp

Active Member
Licensed User
Longtime User
Is there any way to enable the mouse scroll-wheel to zoom in and out, rather than have to use the + or - buttons?

Also, how do you get a Balloon callout when you click a marker... like in GoogleMaps ?

View attachment 145380

Thanks!
Hi,

I didn'tplan to updae this library but feel free to modifiy it according to yours needs.

spsp
 

synasir

Member
Licensed User
Longtime User
Hi, great library here. Using it to download Google Satellite images. However, one question. How does one change the database name "tiles.db3" to something else programmatically by inputting a filename? Thanks.
 

spsp

Active Member
Licensed User
Longtime User
Hi, great library here. Using it to download Google Satellite images. However, one question. How does one change the database name "tiles.db3" to something else programmatically by inputting a filename? Thanks.
Hi,

In clTileManager.bas, change the name in the dbInit sub.

Maybe, add a constant fDataBaseName in the class, and use it in the dbInit sub

spsp
 

papajds

Member
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, I discovered this subject, and very impressive.
I am new to B4A, and I am testing this project out of curiosity
question: is it possible to change the texts of the options buttons of the map, or to change the language?
THANKS
Bye
Jo
 

spsp

Active Member
Licensed User
Longtime User
Hello, I discovered this subject, and very impressive.
I am new to B4A, and I am testing this project out of curiosity
question: is it possible to change the texts of the options buttons of the map, or to change the language?
THANKS
Bye
Jo
Hi,

the file 'menu.json' contains menu options. it is used in the B4XMainPage module (sub Private Sub fcvMap_MenuClicked)

spsp
 

papajds

Member
Hi,

Yes, I saw, but if I change something in this file, it is recreated identically I even tried to delete it, it recreates itself when the program runs.

Jo
 

papajds

Member
Hi,

I found why
the files were copied from "shared files" each time the program was launched...I was not modifying the right files.

thanks
Jo
 

spsp

Active Member
Licensed User
Longtime User
Hi,

I found why
the files were copied from "shared files" each time the program was launched...I was not modifying the right files.

thanks
Jo
H,

Yes the copy is made by this line in B4XMainPage module :
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"

spsp
 

papajds

Member
Hi,

I would like to try with a button to place a marker on the map at the current coordinates.
but with each click, the application “crash”
I have the message:
java.lang.Exception: Sub button1_click signature does not match expected signature.

Any ideas ?

thanks

le code :

private Sub Button1_Click(aLatLng As TMapLatLng)
Dim d As Map=CreateMap("lat":aLatLng.fLat,"lng":aLatLng.fLng)
fcvMap.CenterLatLng=coMapUtilities.initLatLng(d.Get("lat"),d.Get("lng"))
fcvMap.draw
End Sub
 

spsp

Active Member
Licensed User
Longtime User
Hi,

I would like to try with a button to place a marker on the map at the current coordinates.
but with each click, the application “crash”
I have the message:
java.lang.Exception: Sub button1_click signature does not match expected signature.

Any ideas ?

thanks

le code :

private Sub Button1_Click(aLatLng As TMapLatLng)
Dim d As Map=CreateMap("lat":aLatLng.fLat,"lng":aLatLng.fLng)
fcvMap.CenterLatLng=coMapUtilities.initLatLng(d.Get("lat"),d.Get("lng"))
fcvMap.draw
End Sub
Hi,

The signature for a click on a button is
private sub button1_click
...
end sub

there is no parameters

if you want respond to a click on the map, take a look at this sub in the B4XMainPage
private Sub fcvmap_mapClicked(aLatLng As TMapLatLng)
.....
End Sub

spsp
 

papajds

Member
Hello, and thank you for your response, but I may have expressed myself poorly.
I would like, with a click on a button that I placed on the sheet (button1), to retrieve the coordinates "aLatLng.fLat" and "aLatLng.fLng", and be able to display them, etc...
I've done several tests, and it doesn't work...

THANKS.
Jo
 

spsp

Active Member
Licensed User
Longtime User
Hello, and thank you for your response, but I may have expressed myself poorly.
I would like, with a click on a button that I placed on the sheet (button1), to retrieve the coordinates "aLatLng.fLat" and "aLatLng.fLng", and be able to display them, etc...
I've done several tests, and it doesn't work...

THANKS.
Jo
Hi,
Create a sub for the click évent on the button and retriever lat and lng from the cvmap

Sub button1_click
Dim lat as double=fcvmap.centerLat
Dim lng as double=fcvmap.centerLng
......
End sub

spsp
 

papajds

Member
I created it like this:

Public Sub Button1_Click
Dim lat As Double=fcvMap.CenterLatLng.fLat
Dim lng As Double=fcvMap.CenterLatLng.fLng
Log(lat & "," & lng)
End Sub

and I have the "log" of the position.

I will try to save these coordinates in a file...
And I will be able to test if it also works on the road in GPS tracking by pressing the button regularly, to start.
thank you, it's progressing slowly...I'm starting with B4A
Thanks again .
Jo
 
Top