Azure Maps: Find a Time Zone and UTC Offsets
See more Azure Maps Examples
Finds the IANA time zone for coordinates and reads the standard offset, daylight-saving adjustment, and reference local time. Timezone 1.0 takes latitude before longitude. Omit timeStamp for current information, or supply an ISO 8601 timestamp when the date matters.
The effective UTC offset combines the standard offset and daylight-saving adjustment. Store the zone ID, not just today's offset, when scheduling future events. Not all locations observe daylight saving.
Uses direct Chilkat.Http calls to the Azure public-cloud endpoint. Supply a nonempty subscription_key string in private qa_data/azure/maps.json. Shared-key authentication must be enabled on the Maps account. Keep this file outside source control and public web directories, and do not embed account keys in publicly distributed applications. Microsoft Entra ID is an alternative.
Query parameters are supplied as raw text for Chilkat to encode. The code checks transport status, HTTP status, and JSON parsing separately. For throttling or temporary service failures, use bounded retries and honor Retry-After. HTTP diagnostics can contain credentials and location data; inspect them privately. Calls use verified HTTPS and do not follow redirects.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoConfig
Handle hoHttp
Variant vResponse
Handle hoResponse
Handle hoResult
Variant vQuery
Handle hoQuery
Variant vZones
Handle hoZones
Variant vZone
Handle hoZone
Integer i
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global.UnlockBundle for sample code.
Get Create (RefClass(cComChilkatJsonObject)) To hoConfig
If (Not(IsComObjectCreated(hoConfig))) Begin
Send CreateComObject of hoConfig
End
Set ComStrict Of hoConfig To True
// Private file: {"subscription_key":"YOUR_AZURE_MAPS_KEY"}.
Get ComLoadFile Of hoConfig "qa_data/azure/maps.json" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not load private Azure Maps configuration."
Procedure_Return
End
Get ComJsonTypeOf Of hoConfig "subscription_key" To iTemp1
If (iTemp1 <> 1) Begin
Showln "Missing or invalid subscription_key."
Procedure_Return
End
Get ComStringOfEquals Of hoConfig "subscription_key" "" True To bTemp1
If (bTemp1 = True) Begin
Showln "A nonempty subscription_key is required."
Procedure_Return
End
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComRequireSslCertVerify Of hoHttp To True
Set ComFollowRedirects Of hoHttp To False
Set ComConnectTimeout Of hoHttp To 30
Set ComReadTimeout Of hoHttp To 90
Set ComAccept Of hoHttp To "application/json"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResponse
If (Not(IsComObjectCreated(hoResponse))) Begin
Send CreateComObject of hoResponse
End
Get Create (RefClass(cComChilkatJsonObject)) To hoResult
If (Not(IsComObjectCreated(hoResult))) Begin
Send CreateComObject of hoResult
End
Set ComStrict Of hoResult To True
Get Create (RefClass(cComChilkatJsonObject)) To hoQuery
If (Not(IsComObjectCreated(hoQuery))) Begin
Send CreateComObject of hoQuery
End
// Current Azure Maps operations accept the key as a header.
Get ComStringOf Of hoConfig "subscription_key" To sTemp1
Send ComSetRequestHeader To hoHttp "subscription-key" sTemp1
// Timezone 1.0 uses LATITUDE,LONGITUDE (unlike Search 2026 GeoJSON).
// Omit timeStamp to ask for the current time at the service.
Get ComUpdateString Of hoQuery "api-version" "1.0" To iSuccess
Get ComUpdateString Of hoQuery "query" "47.642282,-122.136833" To iSuccess
Get ComUpdateString Of hoQuery "options" "all" To iSuccess
Get pvComObject of hoQuery to vQuery
Get pvComObject of hoResponse to vResponse
Get ComHttpParams Of hoHttp "GET" "https://atlas.microsoft.com/timezone/byCoordinates/json" vQuery vResponse To iSuccess
// Http methods return false for HTTP errors as well as transport failures.
Get ComStatusCode Of hoResponse To iTemp1
If (iTemp1 = 0) Begin
Showln "No HTTP response. Inspect diagnostics privately; they can contain credentials."
Procedure_Return
End
Get ComStatusCode Of hoResponse To iTemp1
If (iTemp1 <> 200) Begin
Get ComStatusCode Of hoResponse To iTemp1
Showln "HTTP status: " iTemp1
Get ComGetHeaderField Of hoResponse "x-ms-error-code" To sTemp1
Showln "Error code: " sTemp1
Get ComGetHeaderField Of hoResponse "Retry-After" To sTemp1
Showln "Retry-After: " sTemp1
// Correct 400/401/403 errors before retrying. Back off for 429 and transient 5xx.
// Keep response bodies and detailed diagnostics out of public logs.
Procedure_Return
End
If (iSuccess <> True) Begin
Showln "The HTTP response was incomplete."
Procedure_Return
End
Get ComBodyStr Of hoResponse To sTemp1
Get ComLoad Of hoResult sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Expected a well-formed JSON response."
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonArray)) To hoZones
If (Not(IsComObjectCreated(hoZones))) Begin
Send CreateComObject of hoZones
End
Get Create (RefClass(cComChilkatJsonObject)) To hoZone
If (Not(IsComObjectCreated(hoZone))) Begin
Send CreateComObject of hoZone
End
Get pvComObject of hoZones to vZones
Get ComArrayOf2 Of hoResult "timeZones" vZones To iSuccess
If (iSuccess <> True) Begin
Showln "Expected timeZones array."
Procedure_Return
End
Get ComSize Of hoZones To iTemp1
If (iTemp1 = 0) Begin
Showln "No time zone was returned."
Procedure_Return
End
Move 0 To i
While (i < (ComSize(hoZones)))
Get pvComObject of hoZone to vZone
Get ComObjectAt2 Of hoZones i vZone To iSuccess
If (iSuccess <> True) Begin
Showln "Invalid time zone."
Procedure_Return
End
Get ComJsonTypeOf Of hoZone "id" To iTemp1
If (iTemp1 <> 1) Begin
Showln "Missing or invalid id."
Procedure_Return
End
Get ComJsonTypeOf Of hoZone "referenceTime.standardOffset" To iTemp1
If (iTemp1 <> 1) Begin
Showln "Missing or invalid referenceTime.standardOffset."
Procedure_Return
End
Get ComJsonTypeOf Of hoZone "referenceTime.daylightSavings" To iTemp1
If (iTemp1 <> 1) Begin
Showln "Missing or invalid referenceTime.daylightSavings."
Procedure_Return
End
Get ComJsonTypeOf Of hoZone "referenceTime.wallTime" To iTemp1
If (iTemp1 <> 1) Begin
Showln "Missing or invalid referenceTime.wallTime."
Procedure_Return
End
Get ComStringOf Of hoZone "id" To sTemp1
Showln "IANA time zone: " sTemp1
Get ComStringOf Of hoZone "referenceTime.standardOffset" To sTemp1
Showln "Standard UTC offset: " sTemp1
Get ComStringOf Of hoZone "referenceTime.daylightSavings" To sTemp1
Showln "Daylight-saving adjustment: " sTemp1
Get ComStringOf Of hoZone "referenceTime.wallTime" To sTemp1
Showln "Local time: " sTemp1
// Effective offset is standardOffset plus daylightSavings, not either alone.
// Preserve the IANA ID: offsets can change with date and local rules.
Move (i + 1) To i
Loop
End_Procedure