Android Question How to make an api call with parameters to the express server using b4a?

sneha Narvekar

New Member
Sorry m new to b4a and dont understand how to make an api call.
Basically i want to take the gps coordinates of the current location and send it to the server.
The lat and long will be the parameters in the api call. Can someone please please help me out? Eagerly waiting for the reply. Thanks in advance.
 

DonManfred

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/threads/okhttp-replaces-the-http-library.54723/

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim job1 As HttpJob
    job1.Initialize("Job1", Me)
    job1.Download("https://donmanfred.basic4android.de/?lat=1.3457&lon=54.76563")
End Sub



Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1"
                'print the result to the logs
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Surely the call depends on the api. Check the Documentation of the Api you want to use.

okhttputils2 is the way to go.
 
Upvote 0

fricentric

Member
Licensed User
Longtime User
Q1. Does the gps coordinates(lat and lng) take time to load the screen? 15 mins after running the project i get the gps coordinates. y so?
Q2. if i implement the api call inside the gps project that has to send the current gps coordinates(lat and lng) to the server, i get an error. The error snapshot is attached. The longitude is not displayed on the screen leaving behind the json response which is in the snapshot.
 

Attachments

  • Screenshot_2017-01-05-12-06-34.png
    Screenshot_2017-01-05-12-06-34.png
    62.7 KB · Views: 140
Upvote 0
Top