request geolocation perm
This commit is contained in:
parent
197ff18efd
commit
3b0d69b4c9
@ -12,13 +12,15 @@ import {AgmCoreModule} from "@agm/core";
|
|||||||
import {MaterialModule} from "./material.module";
|
import {MaterialModule} from "./material.module";
|
||||||
import {CalibrateComponent} from "./map/calibrate/calibrate.component";
|
import {CalibrateComponent} from "./map/calibrate/calibrate.component";
|
||||||
import {MatInputModule} from "@angular/material";
|
import {MatInputModule} from "@angular/material";
|
||||||
|
import {PermissionsComponent} from "./permissions/permissions.component";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
CalibrateComponent,
|
CalibrateComponent,
|
||||||
HomeComponent,
|
HomeComponent,
|
||||||
MapComponent
|
MapComponent,
|
||||||
|
PermissionsComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
AgmCoreModule.forRoot({apiKey: 'AIzaSyDFtvCY6nH_HUoTBNf_5b-E8nRweSLYtxE'}),
|
AgmCoreModule.forRoot({apiKey: 'AIzaSyDFtvCY6nH_HUoTBNf_5b-E8nRweSLYtxE'}),
|
||||||
@ -31,7 +33,7 @@ import {MatInputModule} from "@angular/material";
|
|||||||
MatInputModule,
|
MatInputModule,
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
entryComponents: [CalibrateComponent],
|
entryComponents: [CalibrateComponent, PermissionsComponent],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
MatBottomSheetModule,
|
MatBottomSheetModule,
|
||||||
MatButtonModule, MatDividerModule, MatFormFieldModule,
|
MatButtonModule, MatDialogModule, MatDividerModule, MatFormFieldModule,
|
||||||
MatIconModule, MatInputModule, MatMenuModule, MatSliderModule,
|
MatIconModule, MatInputModule, MatMenuModule, MatSliderModule,
|
||||||
MatSnackBarModule,
|
MatSnackBarModule,
|
||||||
MatToolbarModule
|
MatToolbarModule
|
||||||
@ -10,6 +10,7 @@ import {NgModule} from "@angular/core";
|
|||||||
export const materialModules = [
|
export const materialModules = [
|
||||||
MatBottomSheetModule,
|
MatBottomSheetModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
|
MatDialogModule,
|
||||||
MatDividerModule,
|
MatDividerModule,
|
||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
|
10
src/app/permissions/permissions.component.html
Normal file
10
src/app/permissions/permissions.component.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<div mat-dialog-content>
|
||||||
|
<div class="d-flex">
|
||||||
|
<div><mat-icon class="mr-2">{{icon}}</mat-icon></div>
|
||||||
|
<div><p class="d-inline">{{message}}</p></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div mat-dialog-actions class="float-right">
|
||||||
|
<button mat-button [mat-dialog-close]="false">No Thanks</button>
|
||||||
|
<button mat-button [mat-dialog-close]="true">Ok</button>
|
||||||
|
</div>
|
16
src/app/permissions/permissions.component.ts
Normal file
16
src/app/permissions/permissions.component.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Component, Inject } from "@angular/core";
|
||||||
|
import { MAT_DIALOG_DATA } from "@angular/material";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'permissions',
|
||||||
|
templateUrl: 'permissions.component.html'
|
||||||
|
})
|
||||||
|
export class PermissionsComponent {
|
||||||
|
icon: string;
|
||||||
|
message: string;
|
||||||
|
|
||||||
|
constructor(@Inject(MAT_DIALOG_DATA) data) {
|
||||||
|
this.icon = data.icon;
|
||||||
|
this.message = data.message;
|
||||||
|
}
|
||||||
|
}
|
18
src/app/permissions/permissions.service.ts
Normal file
18
src/app/permissions/permissions.service.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import {Injectable} from "@angular/core";
|
||||||
|
import {MatDialog} from "@angular/material";
|
||||||
|
import {PermissionsComponent} from "./permissions.component";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class PermissionsService {
|
||||||
|
constructor(private dialog: MatDialog) { }
|
||||||
|
|
||||||
|
async requestPermission(name: string, icon: string, message: string) {
|
||||||
|
let perm = await navigator['permissions'].query({name: name});
|
||||||
|
if (perm.state == 'prompt') {
|
||||||
|
return await this.dialog.open(PermissionsComponent, {autoFocus: false, data: {icon: icon, message: message}}).afterClosed().toPromise();
|
||||||
|
}
|
||||||
|
return perm.state == 'granted'
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import {EventEmitter, Injectable} from '@angular/core';
|
import {EventEmitter, Injectable} from '@angular/core';
|
||||||
import {BehaviorSubject, combineLatest} from "rxjs";
|
import {BehaviorSubject, combineLatest} from "rxjs";
|
||||||
import {debounceTime} from "rxjs/operators";
|
import {debounceTime} from "rxjs/operators";
|
||||||
|
import {PermissionsService} from "../permissions/permissions.service";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -17,7 +18,9 @@ export class PhysicsService {
|
|||||||
position = new BehaviorSubject<Position>(null);
|
position = new BehaviorSubject<Position>(null);
|
||||||
speed = new BehaviorSubject(null);
|
speed = new BehaviorSubject(null);
|
||||||
|
|
||||||
constructor() {
|
constructor(permissionsService: PermissionsService) {
|
||||||
|
permissionsService.requestPermission('geolocation', 'gps_fixed', 'Can we use your location?').then(granted => {
|
||||||
|
if(granted) {
|
||||||
// Gather physical data
|
// Gather physical data
|
||||||
window.addEventListener('deviceorientation', orientation => this.orientation.next(orientation));
|
window.addEventListener('deviceorientation', orientation => this.orientation.next(orientation));
|
||||||
window.addEventListener('devicemotion', motion => this.motion.next(motion));
|
window.addEventListener('devicemotion', motion => this.motion.next(motion));
|
||||||
@ -66,4 +69,6 @@ export class PhysicsService {
|
|||||||
this.info.next(info);
|
this.info.next(info);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user