0
위치를 보려면 nativescript 및 angular로 코드를 작성했습니다.Nativescript 위치 플러그인은 위치 설정 만 열림
내 기기의 GPS가 켜져 있어도 geolocation.isEnabled()
에 은 (는)으로 표시됩니다.
플러스 geolocation.watchLocation(..)
을 실행하면 내 장치에서만 위치 설정이 열립니다. 그리고 오류 메시지와 함께 돌아옵니다 :
Error: Location service is not enabled or using it is not granted.
내 앱에서 위치 정보를 사용할 수없는 이유를 아는 사람이 있습니까?
내 app.compoment.html :
<GridLayout columns="*,*" rows="auto,auto,auto">
<Label text="Geolocation" class="title" row="0" colSpan="2"></Label>
<Button row="1" col="0" text="Start Tracking" (tap)="startTracking()"></Button>
<Button row="1" col="1" text="Stop Tracking" (tap)="stopTracking()"></Button>
<Label row="2" col="0" text="Latitude: {{latitude}}"></Label>
<Label row="2" col="1" text="Longitude: {{longitude}}"></Label>
</GridLayout>
내 app.component.ts :
@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent {
latitude = "42";
longitude = "5";
watchId = 0;
public startTracking() {
console.log("Start Tracking");
/* Check if GPS is enabled. */
if (geolocation.isEnabled()) {
console.log("GPS is enabled.");
} else {
console.log("GPS is disabled.");
}
/* Get Location */
this.watchId = geolocation.watchLocation(function (loc) {
if (loc) {
console.log("Current location is: " + loc);
}
}, function (e) {
console.log("Error: " + e.message);
},
{desiredAccuracy: enums.Accuracy.any, updateDistance: 10, minimumUpdateTime: 1000});
}
public stopTracking() {
console.log("Stop Tracking");
if (this.watchId) {
geolocation.clearWatch(this.watchId);
this.watchId = 0;
}
}
}
나는 해결책을 시도 할 것이다 – Julisch
고마워. 그것은 효과가 있었다. – Julisch
앱 설치시 앱에 이러한 권한을 자동으로 부여하는 방법이 없습니까? 예를 들어, pokemon go를 설치할 때이 앱을 설치하면 위치 서비스에 액세스 할 수 있으며 앱에 요청하지 않아도됩니다. – Starwave