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,944
  • B4Xmap.zip
    23 KB · Views: 2,013
  • B4Xmap.b4xlib
    23.7 KB · Views: 898
Last edited:

spsp

Active Member
Licensed User
Longtime User
New Version :
Add GPS Layer

Show the GPS Position and direction (black circle with blue arrow for direction)

Zip in Post #1 updated
 

drgottjr

Expert
Licensed User
Longtime User
lots of work! i'm guessing geocoding will be included in the next version. in keeping with your osm link, if you need any help with nominatim, let me know.
 

Star-Dust

Expert
Licensed User
Longtime User
Very interesting, good job.
Do you think it can also work on B4J and B4i?
 

spsp

Active Member
Licensed User
Longtime User
lots of work! i'm guessing geocoding will be included in the next version. in keeping with your osm link, if you need any help with nominatim, let me know.

You are right.

Update with search

Click on the map, choose 'Search', enter an address. If found, a marker is create and the map is centered on it.

Zip in post#1 updated

spsp
 

Star-Dust

Expert
Licensed User
Longtime User
This class is now a B4XLib for B4A and B4J, sorry I don't use B4I.

Copy B4Xmap.b4xlib in your additional folder

Two examples : B4Amap.b4a and B4Jmap.b4j

Post #1 updated
Thank's. If you let me I will try to go for B4i in the next few days
 

Kevin Hartin

Active Member
Licensed User
Hi,

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

View attachment 108424

The tiles are retrieved from the internet and cached in a database. You can add markers 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
- Marker Clicked
- Map Clicked
- Center Lat/lng clicked
- Button Menu clicked
- Scale clicked
- Compass Clicked
- GPS Clicked

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
- 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
I will be trying it today both on b4a and b4i...

Can it use offline maps?

Kev
 

spsp

Active Member
Licensed User
Longtime User
I will be trying it today both on b4a and b4i...

Can it use offline maps?

Kev

B4I is not supported, only B4A and B4J

the tiles are retrieved from internet (open street map server) and store in a database. So, offline, you can see tiles that you have already seen once.

spsp
 

spsp

Active Member
Licensed User
Longtime User
The examples are for B4A and B4J. I don´t think it will work on B4i.
You're right, I don't use B4I, only B4A and B4J.

Perhaps it's not difficult to adapt for B4I. Most of the code use B4X element (B4XView,B4XBitmap,B4XCanvas...)
 

Star-Dust

Expert
Licensed User
Longtime User
I have adapted a version for b4i. Obviously it would have been much better to recreate everything with B4XPages, but I don't have the time.

PS. I have not reported everything on B4XLib. If I can in the next few days
PS.2. (Hint) Maybe all panel/pane declarations should be changed in B4XView and created panels with XUI.CreatePanel.
 

Attachments

  • B4i Open Map.zip
    192.9 KB · Views: 507

spsp

Active Member
Licensed User
Longtime User
I have adapted a version for b4i. Obviously it would have been much better to recreate everything with B4XPages, but I don't have the time.

PS. I have not reported everything on B4XLib. If I can in the next few days
PS.2. (Hint) Maybe all panel/pane declarations should be changed in B4XView and created panels with XUI.CreatePanel.

Thank you for your work.

I don't use B4XPage for this project because of the single orientation wich is B4A is a problem for this kind of application.

PS2 : You're right, I will change in the next update

spsp
 
Last edited:

spsp

Active Member
Licensed User
Longtime User
Thanks to Star-Dust for his advices and his translation in B4I

Small update with xui.Createpanel instead "dim p as pane" (B4J) or "dim as panel" (B4A).

B4Xmap.b4xlib updated in Post #1
 
Top