Android Code Snippet [B4X] Free Geolocation Nominatim (Geocoding API)

Here's a demo of how to use the nominatim geocoding API for free.

Note:
There are other geocoding options if you want to know, leave your comments.

Demo file attached

B4X:
Sub GeoCoderNominatim(Query As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Dim Parameter() As String = Array As String ("q", Query, "format", "json", "limit", "1", "addressdetails", "1")
    Try
        j.Initialize("", Me)
        j.Download2("https://nominatim.openstreetmap.org/search", Parameter)
        j.GetRequest.SetHeader("Content-Type","application/json")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        Else
            Log(j.ErrorMessage)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return ResultURL
End Sub

Enter address get location

1624173553150.png
1624173572138.png


Enter location get address

1624173639747.png
1624173664177.png
 

Attachments

  • GeoCoderNominatim.zip
    15.9 KB · Views: 173

Wolli013

Active Member
Licensed User
I want to thank you again for this great code!
Is there also something free where you can calculate the correct distance and travel time?
What is that for in your code?


B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
 

amorosik

Well-Known Member
Licensed User
Top