我正在尝试使用iOS,CLLocationManager,CLLocationManagerDelegate在本地文本CLLocationManagerDelegate应用程序中获取标题值。
LocationService.ts
import { Injectable } from "@angular/core";
@Injectable()
export class LocationService {
private locationManager : CLLocationManager;
constructor() {
this.locationManager = CLLocationManager.alloc().init();
this.locationManager.desiredAccuracy = 3;
this.locationManager.distanceFilter = 0.1;
this.locationManager.headingFilter = 0.1;
this.locationManager.delegate = new LocationMangerDelegate();
this.locationManager.requestWhenInUseAuthorization();
this.locationManager.requestAlwaysAuthorization();
}
requestLocation(): void{
this.locationManager.requestLocation();
}
startUpdatingLocation(): void {
this.locationManager.startUpdatingLocation();
}
startUpdatingHeading(): void {
this.locationManager.startUpdatingHeading();
}
}
class LocationMangerDelegate extends NSObject implements CLLocationManagerDelegate {
public static ObjCProtocols = [CLLocationManagerDelegate];
locationManagerDidUpdateLocations(manager: CLLocationManager, locations: NSArray<CLLocation> | CLLocation[]): void{
console.log('we are in');
};
public locationManagerDidFailWithError(manager: CLLocationManager, error: NSError): void{
console.log('error');
};
public locationManagerDidUpdateHeading(manager: CLLocationManager, newHeading: CLHeading): void{
console.log('updated heading');
};
public locationManagerShouldDisplayHeadingCalibration(manager: CLLocationManager): boolean{
console.log('header calibration');
return true;
};
}
TestComponent.ts
import { LocationService } from "../shared/location.service";
export class TestComponent implements OnInit{
constructor(
private locationService: LocationService) {
this.locationService.startUpdatingHeading();
}
Info.plist
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>magnetometer</string>
<string>gps</string>
<string>location-services</string>
<string>armv7</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Desc</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Des1</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Des7</string>
<key>NSLocationUsageDescription</key>
<string>Desc123</string>
reference.d.ts
/// <reference path="./node_modules/@nativescript/types-ios/complete.d.ts"/>
当我从组件调用startUpdatingHeading方法时,不会触发LocationMangerDelegate类中的locationManagerDidUpdateHeading()方法。
我怎么才能把这事做好?我被困在这里,无法继续前进。
发布于 2022-04-05 19:11:14
I能够使用
private locationManager : CLLocationManager;
constructor() {
this.locationManager = CLLocationManager.alloc().init();
this.locationManager.desiredAccuracy = 3;
this.locationManager.distanceFilter = 0.1;
this.locationManager.headingFilter = 0.1;
}
getDirection(): number {
return this.locationManager?.heading?.trueHeading === undefined ? -1 : this.locationManager?.heading?.trueHeading;
}
https://stackoverflow.com/questions/71681893
复制相似问题