Android Question Use Google Timezone API

Discussion in 'Android Questions' started by Cebuvi, Jul 28, 2015.

  1. Cebuvi

    Cebuvi Member Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Cebuvi

    Cebuvi Member Licensed User

    Thank you,

    It works perfectly.
     
  4. DonManfred

    DonManfred Expert Licensed User

    can you share your solution for the other people who will search for such solution in future?
     
  5. Cebuvi

    Cebuvi Member Licensed 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

    Code:
    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
     
    Kwame Twum, Erel and DonManfred like this.
Loading...