Android Question Really working on Android mapping systems, for beginners

Lakhtin_V

Active Member
Licensed User
Longtime User
In this forum, many examples of cartographic information have been discussed. But I can not choose the option that meets my requirements.
1. Ease of embedding code into the Android application.
2. Ability to set the coordinates of the center of the map and the scale of the map display
3. Displaying a group of markers or drawings on the map.
4. Minimal effort to register an API key.
5. If possible, no payment for the use of the mapping system.
I tried the previously published examples using Google and Open Street Map, but they give an error, probably because Android versions change and the API functionality itself changes. Therefore, who can advise a really working example on the latest versions of Android and on the latest versions of B4X. Previously, I created an application using Google maps using a class, but now it only displays a developer-only label on the screen.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
As simple as it gets

B4X:
private Sub ShowMap
    
    Try
        
        Dim Intent1 As Intent
        Dim urlMap As String="https://www.google.com/maps/search/"
        Dim su As StringUtils
        Dim Address As String
            
        Address="45 West 21 street New York, NY 10010"
        Address=Address.Replace(CRLF," ")       
        Address=su.EncodeUrl(Address,"UTF-8")           
        urlMap=urlMap & Address
                
        Intent1.Initialize(Intent1.ACTION_VIEW,urlMap)
        Intent1.SetComponent("googlemaps")
        StartActivity(Intent1)
    Catch
        Log("ShowMap " & LastException.Message)
       
    End Try
    
End Sub
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
As simple as it gets

B4X:
private Sub ShowMap
   
    Try
       
        Dim Intent1 As Intent
        Dim urlMap As String="https://www.google.com/maps/search/"
        Dim su As StringUtils
        Dim Address As String
           
        Address="45 West 21 street New York, NY 10010"
        Address=Address.Replace(CRLF," ")      
        Address=su.EncodeUrl(Address,"UTF-8")          
        urlMap=urlMap & Address
               
        Intent1.Initialize(Intent1.ACTION_VIEW,urlMap)
        Intent1.SetComponent("googlemaps")
        StartActivity(Intent1)
    Catch
        Log("ShowMap " & LastException.Message)
      
    End Try
   
End Sub
In the proposed version, there is no setting the map center by coordinates and there is no way to display markers. But the example is interesting because it is simple. The code is probably not complete, it is not clear in which view element the map will be reflected.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
In the proposed version, there is no setting the map center by coordinates and there is no way to display markers. But the example is interesting because it is simple. The code is probably not complete, it is not clear in which view element the map will be reflected.
it will use the intent in which the map will be shown. That is it. Just try it as is.

Please see the attached screenshot - how it looks in the app
 

Attachments

  • Screenshot_20221212-115849.png
    Screenshot_20221212-115849.png
    406.7 KB · Views: 132
Last edited:
Upvote 0

josejad

Expert
Licensed User
Longtime User
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Thanks for the help, I tried this option. It does not work for me, the problem is in the restrictions on loading tiles. I found a static API request that is convenient for me.
https://static-maps.yandex.ru/1.x/?...z=7&l=map&pt=51.920,43.536,pmwtm1~51.64,43.76
But I do not know how to get the results of this query in the form of a map image and display it on the panel. In the browser this request works fine.
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Is static-maps.yandex.ru a FREE Service?
If yes then you should add a tileprovider using this one.

I can not help build one for Open Street Map viewer though.
Yes Yandex service is free. But I don't want to use tile download tiles technology and have an interactive live map. For my tasks, a dead static image is enough, please help with the code how to display it on the screen.
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
I can NOT help with anything regarding Open Street Map Viewer.

I always use Googlemaps
I was hoping to use my YANDEX static api request just like you do with Google's satic api request. In fact, the code will only have a different URL string, all other lines code, not change, everything will remain as in Google
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Thanks for the help, I tried this option. It does not work for me, the problem is in the restrictions on loading tiles. I found a static API request that is convenient for me.
https://static-maps.yandex.ru/1.x/?...z=7&l=map&pt=51.920,43.536,pmwtm1~51.64,43.76
But I do not know how to get the results of this query in the form of a map image and display it on the panel. In the browser this request works fine.
Not sure what exactly your problem is, but I just checked in my app and downloading of tiles failed.
This was only for a few tiles and haven't downloaded for a few years, so I am not a heavy user.
I then changed the Header string:

B4X:
'Get Tile from internet openstreemap website, note maximum zoom level is 19
Public Sub getTileFromInternet(iZ As Int,iX As Int,iY As Int) As ResumableSub
   
    Dim j As HttpJob
    Dim bmp As B4XBitmap
    Dim strTiles As String = iZ & "/" & iX & "/" & iY & ".png"
   
    Try
        j.Initialize("", Me)
        j.Download("https://a.tile.openstreetmap.org/" & strTiles)
       
        '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 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10")
       
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Try
                bmp=j.GetBitmap
            Catch
                Log("no tile obtained!")
                Log(LastException.Message)
            End Try
        End If
    Catch
        Log("no connection to tile server!")
        Log(LastException.Message)
    End Try
   
    If j.IsInitialized Then
        j.Release
    End If
   
    Return bmp
   
End Sub

And all working fine again.

RBS
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
How to find out the parameters iZ, iX, iY , which are needed to load tiles. I only know the coordinates of the center of the map? The proposed technology does not allow displaying markers inside the map.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
How to find out the parameters iZ, iX, iY , which are needed to load tiles. I only know the coordinates of the center of the map? The proposed technology does not allow displaying markers inside the map.
As Don Manfred said, best to start a new thread.
There is no problem at all showing markers in the map and I am using this in my app.

RBS
 
Upvote 0

Sailboat11

Member
Licensed User
I’m an old programmer. Old programing is pretty-simple. I take any map graphic off the Internet that free to take and program it into a useful map for a computer. You determine a left and right and a top and bottom for the map and that gives you the scale. I use a button for a movable object that represents the device with lines connecting each position for tracking. In most applications, I make the button invisible, so you only see track lines. You parse the Lat/Long coordinates using the GPS Library to move the button. You can use small buttons of different colors as static markers. The way I test my maps is to replace the dynamic input with a static coordinate of a known location.
 

Attachments

  • roundrobin.PNG
    440.7 KB · Views: 56
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I’m an old programmer. Old programing is pretty-simple. I take any map graphic off the Internet that free to take and program it into a useful map for a computer. You determine a left and right and a top and bottom for the map and that gives you the scale. I use a button for a movable object that represents the device with lines connecting each position for tracking. In most applications, I make the button invisible, so you only see track lines. You parse the Lat/Long coordinates using the GPS Library to move the button. You can use small buttons of different colors as static markers. The way I test my maps is to replace the dynamic input with a static coordinate of a known location.
How about zooming?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
One of the controls at the bottom of the graphic, that my picture didn't get is a "copy" button. It sends a copy to the Gallery. Once it gets there, you can zoom, edit or email the picture.
OK, that is interesting.
Wonder how it compares to the usual way to handle maps, that is with tiles.

RBS
 
Upvote 0
Top