Android Question Use Google Timezone API

Cebuvi

Active Member
Licensed User
Longtime User
Hi,

Is it possible to use the Google TimeZone API to determine timezone from latitude/longitude?

In what other way could be determined? (Without using the Google API)

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
It works perfectly.
can you share your solution for the other people who will search for such solution in future?
 
Upvote 0

Cebuvi

Active Member
Licensed User
Longtime User
Hi,

The first is to create or select a project in the Google Developers Console and enable the API for the TimeZone
( see the Erel link: https://developers.google.com/maps/documentation/timezone/intro?hl=en )

And this is the example of my code

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private lblTexto As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Dim Fecha As Long
    Dim url, Lat, Lon, keyAPI As String
    Dim TZjob As HttpJob
   
    Activity.LoadLayout("ly1")
   
    ' timestamp
    Fecha=DateTime.DateParse(DateTime.Date(DateTime.Now))/1000
   
    ' location
    Lat="42.45"       
    Lon="-2.45"
   
    ' Key API
    keyAPI=your code API
   
    TZjob.Initialize("TZjob", Me)
   
    url="https://maps.googleapis.com/maps/api/timezone/json?location=" & Lat & "," & Lon & "&timestamp=" & Fecha & "&key=" & keyAPI
   
    TZjob.PostString(url,"")

   
End Sub
Sub JobDone (Job As HttpJob)
    Dim map1 As Map
    Dim JSON As JSONParser
    If Job.Success = True Then
       
        JSON.Initialize(Job.GetString)
        map1 = JSON.NextObject
        lblTexto.Text=map1.Get("timeZoneId") & CRLF & map1.Get("dstOffset") & CRLF & map1.Get("rawOffset") & CRLF & map1.Get("timeZoneName")
       
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

I hope it's helpful

Cesar
 
Upvote 0
Top