Can I get a fix on your Location in AL?

In this video, I show you can get GeoLocation out of Business Central in AL code, check it out:

https://youtu.be/NknO9gry6Vg

In this video, Erik demonstrates how to use the Geolocation API in Business Central’s AL language to get the GPS coordinates of the device running the browser. It’s a surprisingly straightforward feature that lets your AL code tap into the same location services that power Google Maps in your browser — and it works in SaaS, despite what the official documentation might suggest.

The Documentation Problem

Erik starts by pointing out an important caveat: the official Microsoft documentation page titled “Implementing Location in AL” contains a lot of content about implementing geolocation using .NET interop, which only works on-premises. This might lead you to believe that geolocation functionality is limited to on-prem deployments — but that’s not the case.

The reality is that Microsoft’s System Application (available on GitHub in the ALAppExtensions repository) includes a Geolocation module that has existed since at least version 17. This module includes a codeunit and a page that provide geolocation capabilities that work in SaaS as well. The documentation for these system application modules lives separately from the main docs, which can be confusing. Erik’s advice: when you’re wondering how something works in the system application, check the ALAppExtensions repository on GitHub — it often has documentation that the main docs site lacks.

The Geolocation Module

The Geolocation module in the system application consists of two main objects:

  • Codeunit Geolocation — the primary interface you’ll use in your code
  • Page Geolocation — a supporting page used by the codeunit internally

While you can use the page directly, it works best in conjunction with the codeunit, since the page is designed to be called by the codeunit behind the scenes.

Implementing Geolocation in AL

Erik builds a simple example using a page extension on the Customer List. The approach is straightforward:

  1. Create an instance of the Geolocation codeunit
  2. Optionally enable high accuracy with SetHighAccuracy(true)
  3. Call RequestGeolocation() to ask the browser for the device’s location
  4. If the request succeeds, retrieve the coordinates with GetGeolocation(Lat, Long)

Here’s the complete source code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    var
        GeoLocation: Codeunit Geolocation;
        Lat, Long : Decimal;
    begin
        GeoLocation.SetHighAccuracy(true);
        if GeoLocation.RequestGeolocation() then begin
            GeoLocation.GetGeolocation(Lat, Long);
            Message('%1 %2', Lat, long);
        end;
    end;
}

When Erik runs this in his Docker-based development environment, the page opens, the browser prompts for location permission, and the coordinates are returned — correctly showing his location just north of the 49th parallel on the west coast.

Browser Security and HTTP Considerations

There’s an important practical detail when developing locally: geolocation APIs in modern browsers require a secure context (HTTPS). If you’re running Business Central over plain HTTP (common in Docker development environments), you’ll need to configure your browser to treat your local URL as secure.

In Microsoft Edge (or Chrome), you can do this by navigating to:

edge://flags

Then search for “Insecure origins treated as secure” and add your development URL. This allows the browser’s geolocation API to work even over HTTP during development.

Important Limitation: Client-Side Only

Erik highlights a critical constraint: geolocation only works when there is a client (browser) involved. The RequestGeolocation() call contacts the browser and asks it for the device’s location — the same mechanism used when you visit Google Maps and it shows your current position.

This means geolocation will not work in a Job Queue. Job Queues run on the server without a browser session, so there’s no client to ask “where are you?” Keep this in mind when designing solutions that depend on location data.

High Accuracy Mode

The SetHighAccuracy(true) method tells the browser to use the most precise location source available. On a desktop browser, this may not make a noticeable difference since location is typically determined by IP address or Wi-Fi triangulation. However, on a device with an actual GPS chip — such as a phone or tablet — enabling high accuracy will use the GPS hardware to return a much more precise location rather than relying on less accurate methods.

Summary

Getting device location in Business Central AL is simpler than you might expect. The Geolocation codeunit from the system application handles the heavy lifting, and the code is minimal — just request, check, and retrieve. Remember these key points:

  • The Geolocation module works in both SaaS and on-prem, despite what older documentation might suggest
  • It requires a browser/client session — it won’t work in Job Queues or other server-side-only contexts
  • During local development over HTTP, you may need to configure browser flags to allow geolocation
  • Use SetHighAccuracy(true) for more precise results on GPS-enabled devices
  • Check the ALAppExtensions repository on GitHub for system application documentation that may not be on the main docs site