Angular Navigator.getCurrentPosition Тип ошибки Нуль - PullRequest
0 голосов
/ 05 февраля 2019

Все еще новичок, но я действительно хочу понять!

У меня есть функции в моем компоненте, который возвращает локализацию GPS:

  getMyPosition() {
    navigator.geolocation.getCurrentPosition(function (position) {
      console.log("Position : Latitude=" + position.coords.latitude + "Longitude=" + position.coords.longitude);
      console.log(position.coords);
    }, function (error) {
      console.log("Erreur de géoloc N°" + error.code + " : " + error.message);
      console.log(error);
    });
  }

И моя HTML-страница:

<div align="center">
        <h2>Get GPS Coords</h2>
        <br>
        <h3>to offer you the best service, we need to know your gps position</h3>
        <form [formGroup]="signUpForm4" (ngSubmit)="onSubmit()">
                <button mat-fab color="primary" (click)="getMyPosition()">Get GPS!</button>
                <br>


                <div class="form-field">

                        <mat-form-field appearance="legacy">
                                <mat-label>Latitude</mat-label>
                                <input matInput formControlName="geoloclatitude">{{ position.coords.latitude}}

                        </mat-form-field>
                </div>
                <br>
                <div class="form-field">

                                <mat-form-field appearance="legacy">
                                        <mat-label>Longitude</mat-label>
                                        <input matInput formControlName="geoloclongitude"> {{position.coords.latitude}}

                                </mat-form-field>
                        </div>
                        <br>
        </form>
        <button mat-fab color="primary" type="submit" [disabled]="signUpForm4.invalid">Go!</button>


        <p class="text-danger">{{ errorMessage }}</p>
</div>

Я хочу заполнить 2 поля ввода Широта и долгота компонентными функциями, когда я нажимаю кнопку Получить GPS!

Все функции работают, я получаю в консоли широту, долготу и все координаты.Кто-то может мне помочь?

: D Довольно плееаааасееее!

...