Skip to content

Commit ed20f3e

Browse files
authored
feat: add support for heading (#78)
1 parent cae28ea commit ed20f3e

12 files changed

Lines changed: 180 additions & 22 deletions

File tree

.github/workflows/continuous_integration.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ jobs:
2929

3030
verify-plugin-ios:
3131
needs: ['setup', 'lint', 'build']
32-
runs-on: 'macos-15'
32+
runs-on: 'macos-26'
3333
timeout-minutes: 30
3434
steps:
3535
- uses: actions/checkout@v5
3636
- name: 'Setup Tools'
3737
uses: ./.github/actions/setup-tools
38+
- name: 'Set Xcode version'
39+
run: sudo xcode-select -s /Applications/Xcode_26.3.app/Contents/Developer
3840
- name: 'Verify iOS'
3941
run: npm run verify:ios
4042

@@ -54,12 +56,14 @@ jobs:
5456

5557
build-example-app-ios:
5658
needs: ['verify-plugin-ios', 'verify-plugin-android']
57-
runs-on: 'macos-15'
59+
runs-on: 'macos-26'
5860
timeout-minutes: 30
5961
steps:
6062
- uses: actions/checkout@v5
6163
- name: 'Setup Tools'
6264
uses: ./.github/actions/setup-tools
65+
- name: 'Set Xcode version'
66+
run: sudo xcode-select -s /Applications/Xcode_26.3.app/Contents/Developer
6367
- name: 'Prepare example app'
6468
uses: ./.github/actions/prepare-example-app
6569
- name: 'Build iOS example app'

CapacitorGeolocation.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ Pod::Spec.new do |s|
1313
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
1414
s.ios.deployment_target = '15.0'
1515
s.dependency 'Capacitor'
16-
s.dependency 'IONGeolocationLib', spec='2.0.0'
16+
s.dependency 'IONGeolocationLib', '2.1.0'
1717
s.swift_version = '5.1'
1818
end

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
],
1212
dependencies: [
1313
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
14-
.package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "2.0.0")
14+
.package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "2.1.0")
1515
],
1616
targets: [
1717
.target(

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ Not available on web.
159159

160160
#### Position
161161

162-
| Prop | Type | Description | Since |
163-
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ----- |
164-
| **`timestamp`** | <code>number</code> | Creation timestamp for coords | 1.0.0 |
165-
| **`coords`** | <code>{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number \| null; altitude: number \| null; speed: number \| null; heading: number \| null; }</code> | The GPS coordinates along with the accuracy of the data | 1.0.0 |
162+
| Prop | Type | Description | Since |
163+
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ----- |
164+
| **`timestamp`** | <code>number</code> | Creation timestamp for coords | 1.0.0 |
165+
| **`coords`** | <code>{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number \| null; altitude: number \| null; speed: number \| null; heading: number \| null; magneticHeading: number \| null; trueHeading: number \| null; headingAccuracy: number \| null; course: number \| null; }</code> | The GPS coordinates along with the accuracy of the data | 1.0.0 |
166166

167167

168168
#### PositionOptions

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ dependencies {
8181
implementation project(':capacitor-android')
8282
}
8383

84-
implementation("io.ionic.libs:iongeolocation-android:2.1.0")
84+
implementation("io.ionic.libs:iongeolocation-android:2.2.0")
8585
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
8686

8787
implementation 'com.google.code.gson:gson:2.13.2'

android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationPlugin.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ class GeolocationPlugin : Plugin() {
254254
put("altitude", locationResult.altitude)
255255
locationResult.altitudeAccuracy?.let { put("altitudeAccuracy", it) }
256256
put("speed", locationResult.speed)
257-
put("heading", locationResult.heading)
257+
put("heading", if (locationResult.heading != -1f) locationResult.heading else null)
258+
put("magneticHeading", locationResult.magneticHeading)
259+
put("trueHeading", locationResult.trueHeading)
260+
put("headingAccuracy", locationResult.headingAccuracy)
261+
put("course", locationResult.course)
258262
}
259263
return JSObject().apply {
260264
put("timestamp", locationResult.timestamp)

example-app/src/js/capacitor-welcome.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,46 @@ window.customElements.define(
207207
}
208208
const timeRepresentation = location.timestamp ? new Date(location.timestamp).toISOString() : '-';
209209
stringRepresentation += `- Time: ${timeRepresentation}\n`;
210-
stringRepresentation += `- Latitute: ${location?.coords.latitude}\n- Longitude: ${location?.coords.longitude}\n`;
211-
if (location?.coords.altitude || location?.coords.heading || location?.coords.speed) {
212-
stringRepresentation += `- Altitude: ${location?.coords.altitude}\n- Heading: ${location?.coords.heading}\n- Speed: ${location?.coords.speed}\n`;
213-
}
210+
stringRepresentation += `- Latitude: ${location?.coords.latitude}\n- Longitude: ${location?.coords.longitude}\n`;
214211
stringRepresentation += `- Accuracy: ${location?.coords.accuracy}\n`;
215-
if (location?.coords.altitudeAccuracy) {
216-
stringRepresentation += `- Altitude accuracy: ${location?.coords.altitudeAccuracy}\n`;
212+
stringRepresentation += `- Altitude: ${location?.coords.altitude}\n`;
213+
stringRepresentation += `- Altitude accuracy: ${location?.coords.altitudeAccuracy}\n`;
214+
stringRepresentation += `- Speed: ${location?.coords.speed}\n`;
215+
216+
if (
217+
location?.coords.heading !== null &&
218+
location?.coords.heading !== undefined &&
219+
location?.coords.heading !== -1
220+
) {
221+
stringRepresentation += `- Heading: ${location.coords.heading}\n`;
222+
}
223+
if (
224+
location?.coords.magneticHeading !== null &&
225+
location?.coords.magneticHeading !== undefined &&
226+
location?.coords.magneticHeading !== -1
227+
) {
228+
stringRepresentation += `- Magnetic Heading: ${location.coords.magneticHeading}\n`;
229+
}
230+
if (
231+
location?.coords.trueHeading !== null &&
232+
location?.coords.trueHeading !== undefined &&
233+
location?.coords.trueHeading !== -1
234+
) {
235+
stringRepresentation += `- True Heading: ${location.coords.trueHeading}\n`;
236+
}
237+
if (
238+
location?.coords.headingAccuracy !== null &&
239+
location?.coords.headingAccuracy !== undefined &&
240+
location?.coords.headingAccuracy !== -1
241+
) {
242+
stringRepresentation += `- Heading Accuracy: ${location.coords.headingAccuracy}\n`;
243+
}
244+
if (
245+
location?.coords.course !== null &&
246+
location?.coords.course !== undefined &&
247+
location?.coords.course !== -1
248+
) {
249+
stringRepresentation += `- Course: ${location.coords.course}\n`;
217250
}
218251
return stringRepresentation;
219252
}

ios/Sources/GeolocationPlugin/GeolocationConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ enum Constants {
3333
static let speed: String = "speed"
3434
static let timestamp: String = "timestamp"
3535
static let altitudeAccuracy: String = "altitudeAccuracy"
36+
static let magneticHeading: String = "magneticHeading"
37+
static let trueHeading: String = "trueHeading"
38+
static let headingAccuracy: String = "headingAccuracy"
39+
static let course: String = "course"
3640
}
3741
}

ios/Sources/GeolocationPlugin/IONGLOCPositionModel+JSONTransformer.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ extension IONGLOCPositionModel {
1010
}
1111

1212
private var coordsJSObject: JSObject {
13-
[
13+
let headingValue = trueHeading ?? magneticHeading ?? (course != -1.0 ? course : nil)
14+
return [
1415
Constants.Position.altitude: altitude,
15-
Constants.Position.heading: course,
16+
Constants.Position.heading: headingValue ?? NSNull(),
17+
Constants.Position.magneticHeading: magneticHeading ?? NSNull(),
18+
Constants.Position.trueHeading: trueHeading ?? NSNull(),
19+
Constants.Position.headingAccuracy: headingAccuracy ?? NSNull(),
20+
Constants.Position.course: course != -1.0 ? course : NSNull(),
1621
Constants.Position.accuracy: horizontalAccuracy,
1722
Constants.Position.latitude: latitude,
1823
Constants.Position.longitude: longitude,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@
8888
"src": "android"
8989
}
9090
}
91-
}
91+
}

0 commit comments

Comments
 (0)