还是菜鸟,但我真的很想了解!
我的组件中有返回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>
当我单击Get Gps时,我想用组件函数填充2 Input字段的经度和纬度!
所有功能都可以在控制台的纬度,经度和所有坐标中使用。 有人可以帮助我吗?
:D漂亮pleeeaaaaseeee!