A Godot Geolocation Plugin for iOS. Compatible with Godot 3.5.1.
- Put the Geolocation-Plugin Folder (containing the .aar and .gdip file) in the
res://ios/plugins
folder in your project - Add iOS Export (
Project > Export...
) - Enable
Geolocation
in thePlugins
-section - Set
NSLocationAlwaysAndWhenInUseUsageDescription
andNSLocationWhenInUseUsageDescription
in thePlugins Plist
-section
request_permission()
[iOS only] - requests authorization and will show the native OS dialog. Theauthorization_changed(int)
signal will be triggered when the user has made their decision. On Android use the native Godot functionOS.request_permissions()
and the Godot signalon_request_permissions_result
-
request_location()
- Requests a single location the set accurarcy. The result will be delivered by thelocation_update
signal. An error might be delivered by theerror
signal (ERROR_DENIED
,ERROR_NETWORK
) -
start_updating_location()
- Start location updates with the set options. Results will be delivered by thelocation_update
signal. An error might be delivered by theerror
signal (ERROR_DENIED
,ERROR_NETWORK
) -
stop_updating_location()
- Stops the location updates.
-
start_updating_heading()
- Start heading updates. Results will be delivered by theheading_update
signal. An error might be delivered by theerror
signal (ERROR_HEADING_FAILURE
) -
stop_updating_heading()
- Stops the heading updates.
-
set_distance_filter(meters:float)
- Set the minimum distance in meters the location has to be different to be delivered bylocation_update
. Default: 0 -
set_desired_accuracy(desired_accuracy_constant:int)
- Set the desired accuracyint
being a constant fromGeolocationDesiredAccuracyConstants
enum. Default:ACCURACY_BEST
-
set_update_interval(seconds:int)
[Android only] - Set the update interval for new locations in seconds. Default: 1 -
set_max_wait_time(seconds:int)
[Android only] - Set the maximum time in seconds you are willing to wait for thelocation_update
signal. This is not a timeout. It actually means that locations will be deferred and delivered in bunches everytimeInSeconds
. Default: 1 -
set_return_string_coordinates(active:bool)
- Set tofalse
if you don't want latitude and longitude to be additionally included as strings in theLocation Data
Dictionary. Default: true -
set_failure_timeout(seconds:int)
- Set the timeout in seconds before an error is reported, when no location could be found. Default: 20 -
set_debug_log_signal(send:bool)
- Set totrue
if you want to receive debug messages from the native plugin through thelog
signal. Default: false -
set_auto_check_location_capability(auto:bool)
[Android only] - Set totrue
if the plugin should automatically check for location capability before requesting a location. Default: false
-
authorization_status() -> int
- returns the current authorization status (EnumGeolocationAuthorizationStatus
) -
allows_full_accuracy() -> bool
- returnstrue
if the user allowed full accuracy -
can_request_permissions() -> bool
- returnstrue
if it is possible to request location permissions. On iOS this is only the case as long the authorization status isPERMISSION_STATUS_UNKNOWN
, on Android it is possible to request permissions for a second time (if the first time only coarse permissions were granted) -
is_updating_location() -> bool
- returns true when the native location manager is active. Might not always report correctly. Stop and Start locations updates if unsure -
is_updating_heading() -> bool
[iOS only for now] - returns true heading is actively updating Might not always report correctly -
should_show_permission_requirement_explanation() -> bool
[Android only] - returns truetrue
when permissions where rejected before and the user needs an explanation why the permissions are neccesary -
request_location_capabilty()
- checks device capability for locartion services. Async result (true
/false
) is delivered bylocation_capability_result
signal -
should_check_location_capability() -> bool
- returns truetrue
when you should manually check for location capability (true
whenset_auto_check_location_capability
isfalse
on Android, alswaysfalse
on iOS)
supports(methodName:string) -> bool
- returnstrue
if the method "methodName" is supported
log(message:string, number:float)
- returns a debug message from the native platform pluginerror(code:int)
- returns an error code (EnumGeolocationErrorCodes
)authorization_changed(authorization_status:int)
[iOS only] - returns an authorization status (EnumGeolocationAuthorizationStatus
)location_update(location:Dictionary)
- returns a Godot Dictionary with location data (seeLocation Data
)heading_update(heading:Dictionary)
[iOS only] - returns a Godot Dictionary with magentic heading data (seeHeading Data
)location_capability_result(capable:bool)
- returns a boolean value.true
means that location capability is available
https://github.com/WolfBearGames/Geolocation-Csharp-Wrapper
https://github.com/WolfBearGames/Geolocation-GDScript-Wrapper
https://github.com/WolfBearGames/GeolocationTestApp
enum geolocation_authorization_status {
PERMISSION_STATUS_UNKNOWN = 1 << 0,
PERMISSION_STATUS_DENIED = 1 << 1,
PERMISSION_STATUS_ALLOWED = 1 << 2
}
enum geolocation_desired_accuracy_constants {
ACCURACY_BEST_FOR_NAVIGATION = 1 << 0,
ACCURACY_BEST = 1 << 1,
ACCURACY_NEAREST_TEN_METERS = 1 << 2,
ACCURACY_HUNDRED_METERS = 1 << 3,
ACCURACY_KILOMETER = 1 << 4,
ACCURACY_THREE_KILOMETER = 1 << 5,
ACCURACY_REDUCED = 1 << 6
}
enum geolocation_error_codes {
ERROR_DENIED = 1 << 0,
ERROR_NETWORK = 1 << 1,
ERROR_HEADING_FAILURE = 1 << 2
ERROR_LOCATION_UNKNOWN = 1 << 3
ERROR_TIMEOUT = 1 << 4
ERROR_UNSUPPORTED = 1 << 5
ERROR_LOCATION_DISABLED = 1 << 6
ERROR_UNKNOWN = 1 << 7
}
public enum GeolocationErrorCodes
{
ERROR_DENIED = 1 << 0,
ERROR_NETWORK = 1 << 1,
ERROR_HEADING_FAILURE = 1 << 2,
ERROR_LOCATION_UNKNOWN = 1 << 3,
ERROR_TIMEOUT = 1 << 4,
ERROR_UNSUPPORTED = 1 << 5,
ERROR_LOCATION_DISABLED = 1 << 6,
ERROR_UNKNOWN = 1 << 7
};
public enum GeolocationAuthorizationStatus
{
PERMISSION_STATUS_UNKNOWN = 1 << 0,
PERMISSION_STATUS_DENIED = 1 << 1,
PERMISSION_STATUS_ALLOWED = 1 << 2,
}
public enum GeolocationDesiredAccuracyConstants
{
ACCURACY_BEST_FOR_NAVIGATION = 1 << 0,
ACCURACY_BEST = 1 << 1,
ACCURACY_NEAREST_TEN_METERS = 1 << 2,
ACCURACY_HUNDRED_METERS = 1 << 3,
ACCURACY_KILOMETER = 1 << 4,
ACCURACY_THREE_KILOMETER = 1 << 5,
ACCURACY_REDUCED = 1 << 6,
}
["latitude"] float
- the current latitude. precision is lost["longitude"] float
- the current latitude. precision is lost["latitude_string"] string
(optional) - the current latitude. convertable to double in C#["longitude_string"] string
(optional) - the current latitude. convertable to double in C#["accuracy"] float
- the current horizontal accuracy in meters["altitude"] float
- the current altitude in meters["altitude_accuracy"] float
- the current vertical accuracy in meters. (-1 when unavailable)["course"] float
- the current heading (in motion). This is the direction the device is travelling in, not the magnetic/compass heading["course_accuracy"] float
- the course accuracy in degrees["speed"] float
- the current speed in m/s["speed_accuracy"] float
- the current speed accuracy in m/s. (-1 when unavailable)["timestamp"] int
- the current time as the number of seconds since 1970-01-01
["magnetic_heading"] float
- the magnetic heading (relative to magnetic noth pole)["true_heading"] float
- the true heading (relative to geographic noth pole)["heading_accuracy"] float
- the heading accuracy in degrees (-1 when unavailable)["timestamp"] int
- the current time as the number of seconds since 1970-01-01
The plugin is based on the official iOS Godot plugins and uses the same scons script to compile (you will need Python and Scons installed):
- Run
./scripts/generate_xcframework.sh geolocation <debug|release|release_debug> <godot_version>
to generatexcframework
with specific configuration.xcframework
allows plugin to support botharm64
device andarm64
simulator. - The result
.xcframework
will be stored in thebin/
folder as well as intermidiate.a
binaries.
Example: ./scripts/generate_xcframework.sh geolocation release 3.x
There is an xCode project under plugins/geolocation.xcodeproj
. You can use xCode to edit source code, but should use the command line scripts to compile (compiling with xCode will lead to ref-counting issues on application exit).
Copyright 2022 Andreas Ritter (www.wolfbeargames.de)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.