Hi,
Further to a post I made in another thread. Below is a service code that can be called to get the elevation data from the google API.
This can be called from an activity with the following code.
If you have any issues with the code then please let me know and I will attempt to answer any questions. If I get chance today, I will created and post a class that will handle everything
Further to a post I made in another thread. Below is a service code that can be called to get the elevation data from the google API.
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private elevationJob As HttpJob
End Sub
Sub Service_Create
elevationJob.Initialize("elevationJob",Me)
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
Sub getElevationData(url As String)
elevationJob.Download(url)
End Sub
Sub JobDone (Job As HttpJob)
If Job.Success = True Then
DecodeJsonResponse(Job.GetString)
Else
'Here is some code to handle an error
End If
Job.Release
End Sub
Sub DecodeJsonResponse(jsonResponse As String)
Dim JSON As JSONParser
Dim Map1 As Map
JSON.Initialize(jsonResponse)
Map1 = JSON.NextObject
Dim m As Map 'helper map for navigating
Dim ResultItems As List
ResultItems = Map1.Get("results")
For i = 0 To ResultItems.Size - 1
m = ResultItems.Get(i)
Next
'Now show the results. These could be assigned to global variable, saved in ini file etc etc
Log(m.Get("elevation"))
Log(m.Get("resolution"))
End Sub
This can be called from an activity with the following code.
B4X:
'Assign the values to the params required by the API request
Dim Latitude As Double = 39.73915360
Dim Longitude As Double = -104.98470340
Dim sensor As Boolean = False
Dim url As String = "http://maps.googleapis.com/maps/api/elevation/json?locations=" & Latitude & "," & Longitude & "&sensor=" & sensor
CallSubDelayed2(getElevationData,"getElevationData",url)
If you have any issues with the code then please let me know and I will attempt to answer any questions. If I get chance today, I will created and post a class that will handle everything