location (GPS)

Type Event
Revision Release 2024.3703
Keywords location, GPS

Overview

These are location events generated by the GPS hardware. They are only sent to the global Runtime object when the app requests them with a statement like Runtime:addEventListener( "location", locationHandler ).

See the individual property documentation pages below for examples.

Gotchas

General

In the location event listener, event.errorCode should be checked in case of a location error.

Android

To enable GPS on Android devices, you must add the following permission(s) to the build.settings file:

settings =
{
    android =
    {
        usesPermissions =
        {
            -- Permission to retrieve current location from the GPS
            "android.permission.ACCESS_FINE_LOCATION",
            -- Permission to retrieve current location from WiFi or cellular service
            "android.permission.ACCESS_COARSE_LOCATION",
        },
    },
}

iOS

On iOS, event.errorCode will be non-nil if the user disabled location services for the app.

macOS

You must adjust your app’s entitlements to use location events for macOS apps. See here for details.

Windows

Location services are not currently supported on Windows. While the Corona Simulator for Windows will synthesize a fake location event for testing purposes, Windows desktop apps will not do this. As a consequence, system.hasEventSource( "location" ) will return true in the Corona Simulator for Windows but false in Windows desktop apps.

Properties

event.accuracy

event.altitude

event.direction

event.errorCode

event.errorMessage

event.latitude

event.longitude

event.name

event.speed

event.time