Android Question ResponseError

Almora

Well-Known Member
Licensed User
Longtime User

B4X:
    Dim GetAddressJob As HttpJob
    GetAddressJob.Initialize("GetAddress", Me)
    
    
    GetAddressJob.Download2("https://api.open-meteo.com/v1/elevation", Array As String("latitude", lat & "&" & "longitude" & lon))

    Wait For (GetAddressJob) JobDone(GetAddressJob As HttpJob)
    If GetAddressJob.Success Then
        
        Dim parser As JSONParser
        parser.Initialize(GetAddressJob.GetString)
        Dim root As Map = parser.NextObject
 
 
        Dim elevation As List = root.Get("elevation")
        For Each colelevation As Int In elevation
            
            Log("info" &  colelevation)
        Next
 
    End If
    GetAddressJob.Release



Hello, when I parse the address above, it gives this error. I would be happy if you help.. thanks..

ResponseError. Reason: , Response: {"error":true,"reason":"Value at path 'latitude.0' was not of type 'Float'. Data found at 'latitude.0' was not Float."}
 

drgottjr

Expert
Licensed User
Longtime User
and if you accustomed to spelling out your query strings, you can use:
GetAddressJob.Download("https://api.open-meteo.com/v1/elevation" & "?latitude=37.42&longitude=-122.08")

OR:
dim latitude as float = 37.42
dim longitude as float = -122.08
GetAddressJob.Download("https://api.open-meteo.com/v1/elevation" & $"?latitude=${latitude}&longitude=${longitude}"$)

note: GetAddressJob.Download() instead of GetAddressJob.Download2()

note: any geoposition measurements are likely to be doubles, not ints
the request returns 1 measurement, so you don't need a list. just ask for:

Dim elevation As float = root.Get("elevation")
Log(elevation)

note: you only test for success. that's bad:
if getaddressjob.success then
' do something
else ' ERROR!
log(gettaddressjob.errormessage
end if
 
Upvote 0

Almora

Well-Known Member
Licensed User
Longtime User
B4X:
....

    Dim GetAddressJob As HttpJob
    GetAddressJob.Initialize("GetAddress", Me)
    
    '    https://api.open-meteo.com/v1/elevation?latitude=37.42&longitude=-122.08

 '  GetAddressJob.Download2("https://api.open-meteo.com/v1/elevation", Array As String("latitude", lat, "longitude", lon))

    GetAddressJob.Download("https://api.open-meteo.com/v1/elevation" & $"?latitude=${lat}&longitude=${lon}"$)

    Wait For (GetAddressJob) JobDone(GetAddressJob As HttpJob)
    If GetAddressJob.Success Then
        
        Dim parser As JSONParser
        parser.Initialize(GetAddressJob.GetString)
        Dim root As Map = parser.NextObject
 
 
        Dim elevation As Float = root.Get("elevation")

            Log("i" &  elevation)
 
    End If
    GetAddressJob.Release
    
    .....

I tried the methods but it didn't work..

ResponseError. Reason: java.net.UnknownHostException: Unable to resolve host "api.open-meteo.com": No address associated with hostname, Response:
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i don't post without having first tried what i'm going to post. both methods suggested work. they both return 4.0 elevation. the response error you show either indicates you weren't online when you tried or the url is incorrect. since i pasted the url you provided and since it works for me, i have to assume you weren't online. can't help you with that. (also - although having nothing to do with the error - i don't see that you initialized lat and lon).
 
Upvote 0

Almora

Well-Known Member
Licensed User
Longtime User
okay, I'll try again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…