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 SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global.UnlockBundle for sample code.
DECLARE @config int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @config OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @config, 'Strict', 1
-- Private file: {"subscription_key":"YOUR_AZURE_MAPS_KEY"}.
EXEC sp_OAMethod @config, 'LoadFile', @success OUT, 'qa_data/azure/maps.json'
IF @success <> 1
BEGIN
PRINT 'Could not load private Azure Maps configuration.'
EXEC @hr = sp_OADestroy @config
RETURN
END
EXEC sp_OAMethod @config, 'JsonTypeOf', @iTmp0 OUT, 'subscription_key'
IF @iTmp0 <> 1
BEGIN
PRINT 'Missing or invalid subscription_key.'
EXEC @hr = sp_OADestroy @config
RETURN
END
EXEC sp_OAMethod @config, 'StringOfEquals', @iTmp0 OUT, 'subscription_key', '', 1
IF @iTmp0 = 1
BEGIN
PRINT 'A nonempty subscription_key is required.'
EXEC @hr = sp_OADestroy @config
RETURN
END
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
EXEC sp_OASetProperty @http, 'RequireSslCertVerify', 1
EXEC sp_OASetProperty @http, 'FollowRedirects', 0
EXEC sp_OASetProperty @http, 'ConnectTimeout', 30
EXEC sp_OASetProperty @http, 'ReadTimeout', 90
EXEC sp_OASetProperty @http, 'Accept', 'application/json'
DECLARE @response int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @response OUT
DECLARE @result int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @result OUT
EXEC sp_OASetProperty @result, 'Strict', 1
DECLARE @query int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @query OUT
-- Current Azure Maps operations accept the key as a header.
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'subscription_key'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'subscription-key', @sTmp0
-- Timezone 1.0 uses LATITUDE,LONGITUDE (unlike Search 2026 GeoJSON).
-- Omit timeStamp to ask for the current time at the service.
EXEC sp_OAMethod @query, 'UpdateString', @success OUT, 'api-version', '1.0'
EXEC sp_OAMethod @query, 'UpdateString', @success OUT, 'query', '47.642282,-122.136833'
EXEC sp_OAMethod @query, 'UpdateString', @success OUT, 'options', 'all'
EXEC sp_OAMethod @http, 'HttpParams', @success OUT, 'GET', 'https://atlas.microsoft.com/timezone/byCoordinates/json', @query, @response
-- Http methods return false for HTTP errors as well as transport failures.
EXEC sp_OAGetProperty @response, 'StatusCode', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
PRINT 'No HTTP response. Inspect diagnostics privately; they can contain credentials.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
RETURN
END
EXEC sp_OAGetProperty @response, 'StatusCode', @iTmp0 OUT
IF @iTmp0 <> 200
BEGIN
EXEC sp_OAGetProperty @response, 'StatusCode', @iTmp0 OUT
PRINT 'HTTP status: ' + @iTmp0
EXEC sp_OAMethod @response, 'GetHeaderField', @sTmp0 OUT, 'x-ms-error-code'
PRINT 'Error code: ' + @sTmp0
EXEC sp_OAMethod @response, 'GetHeaderField', @sTmp0 OUT, 'Retry-After'
PRINT 'Retry-After: ' + @sTmp0
-- Correct 400/401/403 errors before retrying. Back off for 429 and transient 5xx.
-- Keep response bodies and detailed diagnostics out of public logs.
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
RETURN
END
IF @success <> 1
BEGIN
PRINT 'The HTTP response was incomplete.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
RETURN
END
EXEC sp_OAGetProperty @response, 'BodyStr', @sTmp0 OUT
EXEC sp_OAMethod @result, 'Load', @success OUT, @sTmp0
IF @success <> 1
BEGIN
PRINT 'Expected a well-formed JSON response.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
RETURN
END
DECLARE @zones int
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @zones OUT
DECLARE @zone int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @zone OUT
EXEC sp_OAMethod @result, 'ArrayOf2', @success OUT, 'timeZones', @zones
IF @success <> 1
BEGIN
PRINT 'Expected timeZones array.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
EXEC sp_OAGetProperty @zones, 'Size', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
PRINT 'No time zone was returned.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
DECLARE @i int
SELECT @i = 0
EXEC sp_OAGetProperty @zones, 'Size', @iTmp0 OUT
WHILE (@i < @iTmp0)
BEGIN
EXEC sp_OAMethod @zones, 'ObjectAt2', @success OUT, @i, @zone
IF @success <> 1
BEGIN
PRINT 'Invalid time zone.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
EXEC sp_OAMethod @zone, 'JsonTypeOf', @iTmp0 OUT, 'id'
IF @iTmp0 <> 1
BEGIN
PRINT 'Missing or invalid id.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
EXEC sp_OAMethod @zone, 'JsonTypeOf', @iTmp0 OUT, 'referenceTime.standardOffset'
IF @iTmp0 <> 1
BEGIN
PRINT 'Missing or invalid referenceTime.standardOffset.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
EXEC sp_OAMethod @zone, 'JsonTypeOf', @iTmp0 OUT, 'referenceTime.daylightSavings'
IF @iTmp0 <> 1
BEGIN
PRINT 'Missing or invalid referenceTime.daylightSavings.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
EXEC sp_OAMethod @zone, 'JsonTypeOf', @iTmp0 OUT, 'referenceTime.wallTime'
IF @iTmp0 <> 1
BEGIN
PRINT 'Missing or invalid referenceTime.wallTime.'
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
RETURN
END
EXEC sp_OAMethod @zone, 'StringOf', @sTmp0 OUT, 'id'
PRINT 'IANA time zone: ' + @sTmp0
EXEC sp_OAMethod @zone, 'StringOf', @sTmp0 OUT, 'referenceTime.standardOffset'
PRINT 'Standard UTC offset: ' + @sTmp0
EXEC sp_OAMethod @zone, 'StringOf', @sTmp0 OUT, 'referenceTime.daylightSavings'
PRINT 'Daylight-saving adjustment: ' + @sTmp0
EXEC sp_OAMethod @zone, 'StringOf', @sTmp0 OUT, 'referenceTime.wallTime'
PRINT 'Local time: ' + @sTmp0
-- Effective offset is standardOffset plus daylightSavings, not either alone.
-- Preserve the IANA ID: offsets can change with date and local rules.
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @query
EXEC @hr = sp_OADestroy @zones
EXEC @hr = sp_OADestroy @zone
END
GO