{"title":"Implementing location in AL","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-implement-location-al/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-implement-location-al, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-implement-location-al","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn how to implement location access in AL for Dynamics 365 Business Central. Enhance your app with GPS capabilities for better customer service.","date":"2026-08-24","meta":{"topic":"concept-article"},"outline":[{"level":2,"title":"Example","slug":"example","at":1324,"chars":3645},{"level":2,"title":"Related information","slug":"related-information","at":4969,"chars":337}],"text":"You can access the location information of a device from the Business Central Web client in the browser and from the Business Central Mobile App. This functionality could be useful in scenarios such as calculating routes from the current location or planning the next round of customer visits based on their addresses.\nYou can also add access to location information to a specific page from the AL Language development environment.\nFor a Dynamics 365 Business Central existing implementation of this, see the `Show On Map` link on the `Customer Card`, which displays a map that shows where your customer is located based on the GPS coordinates and gives directions to reach its location.\n> IMPORTANT\n> Location information is only available on devices that are able to obtain location coordinates, such as using GPS capabilities.\n> IMPORTANT\n> This example uses .NET interoperability, which is only available for on-premises deployments. To use it, you must set `\"target\": \"OnPrem\"` in the app.json file. See Get started with Microsoft .NET Interoperability from AL<devenv-get-started-call-dotnet-from-al>. For online environments, use the Geolocation codeunit in the System Application instead. See https://learn.microsoft.com/dynamics365/business-central/application/system-application/codeunit/system.device.geolocation.\n## Example\nThis example illustrates how to implement the location capability on a page in AL. The example implements a GetLocation action on a page that returns the coordinates of the current customer's address, but doesn't save this information to the database.\nThe example also shows how to specify options for the location functionality such as setting a timeout or enabling high accuracy. Learn more about the options that you can set for location in LocationOptions overview<devenv-location-options>.\n> NOTE\n> To enable the location functionality, you must add the path of the folder containing the `\"Microsoft.Dynamics.Nav.ClientExtensions\"` assembly on the Al: Assembly Probing Paths setting on the User Settings or Workspace Settings so the compiler can access it. See Getting started with Microsoft .NET Interoperability from AL<devenv-get-started-call-dotnet-from-al>.\nThe following code will create two variables; the LocationAvailable variable is a Boolean that checks whether the current device has location capabilities. The Location variable is a DotNet type that gets instantiated by adding code to the OnOpenPage trigger. Then, it will add an action to the page that lets the user retrieve the location information. Finally, the trigger `Location::LocationChanged` is defined to handle the incoming location information.\n```al\npage 50101 \"Card with Location Capability\"\n{\n\n    Caption = 'Card Page';\n    PageType = Card;\n    RefreshOnActivate = true;\n    SourceTable = \"Test Table\";\n\n    layout\n    {\n        area(content)\n        {\n            //...\n        }\n    }\n\n    actions\n    {\n        area(Processing)\n        {\n            action(GetLocation)\n            {\n                Visible = LocationAvailable;\n                Promoted = true;\n                PromotedCategory = Process;\n                PromotedIsBig = true;\n                Image = Map;\n\n                trigger OnAction()\n                begin\n                    LocationOptions := LocationOptions.LocationOptions();\n                    LocationOptions.EnableHighAccuracy := true;\n                    Location.RequestLocationAsync(LocationOptions);\n                end;\n            }\n        }\n\n    }\n\n    trigger OnOpenPage()\n    begin\n        if Location.IsAvailable() then begin\n            Location := Location.Create();\n            LocationAvailable := true;\n        end;\n    end;\n\n    trigger Location::LocationChanged(Location: DotNet Location)\n    begin\n        // Location.Status can be:\n        //      0 = Available\n        //      1 = NoData (no data could be obtained)\n        //      2 = TimedOut (location information not obtained in due time)\n        //      3 = NotAvailable (for example user denied app access to location)\n        if Location.Status = 0 then\n            Message('Your position: %1 %2', Location.Coordinate.Latitude, Location.Coordinate.Longitude)\n        else\n            Message('Position not available');\n    end;\n\n    var\n        [RunOnClient]\n        [WithEvents]\n        Location: DotNet LocationProvider;\n        LocationAvailable: Boolean;\n        LocationOptions: DotNet UT_LocationOptions;\n}\n\ndotnet\n{\n    assembly(\"Microsoft.Dynamics.Nav.ClientExtensions\")\n    {\n\n        type(\"Microsoft.Dynamics.Nav.Client.Capabilities.LocationProvider\"; LocationProvider)\n        {\n\n        }\n\n        type(\"Microsoft.Dynamics.Nav.Client.Capabilities.Location\"; Location)\n        {\n\n        }\n\n        type(\"Microsoft.Dynamics.Nav.Client.Capabilities.LocationOptions\"; UT_LocationOptions)\n        {\n\n        }\n    }\n}\n```\nLearn more about troubleshooting access to location information in /ui-troubleshooting-camera-location.\n## Related information\nGetting started with Microsoft .NET Interoperability from AL<devenv-get-started-call-dotnet-from-al>\nLocationOptions overview<devenv-location-options>\n/ui-troubleshooting-camera-location\ndevenv-implement-camera-al\nRunOnClient property<properties/devenv-properties>\nWithEvents property<properties/devenv-properties>"}