如何使用AGM返回经度和纬度来映射

时间:2018-03-26 07:35:59

标签: angular typescript maps

我使用Angular Google Maps(AGM)来获取所选位置的经度和纬度,并且它成功运行,因为它发送了正确的数据。我想在检索此数据时将标记放在检索到的位置[双向绑定]

component.html:

<agm-map [latitude]="GPSLatitude" [longitude]="GPSLongitude"  (mapClick)="placeMarker($event)">
    <agm-marker [latitude]="GPSLatitude" [longitude]="GPSLongitude"></agm-marker>
</agm-map>    

component.ts:

ngOnInit() {
  this.GPSLatitude = 29.98110768446724; //As Default Value
  this.GPSLongitude= 31.268634796142578; //As Default Value

  this.myform = new FormGroup({
    GPSLatitude: new FormControl(this.GPSLatitude),
    GPSLongitude: new FormControl(this.GPSLongitude),
  })

showData(BranchID){
  this.RData = this.branches.find(n => n.BranchID === BranchID);
  console.log(this.RData) // it retrieve object with saved location correctly
  this.GPSLatitude = this.RData.GPSLatitude;
  this.GPSLongitude = this.RData.GPSLongitude;

  this.myform.controls['GPSLatitude'].setValue(this.RData.GPSLongitude);
  this.myform.controls['GPSLongitude'].setValue(this.RData.GPSLongitude)
  console.log(this.GPSLongitude) // it retrieve right longitude as i saved before in obj
 }

placeMarker($event){
  this.GPSLatitude = $event.coords.lat;
  this.GPSLongitude =  $event.coords.lng;
}

当我将showData标记保持在它的默认值时..如何将标记的位置更改为检索到的经度和纬度

0 个答案:

没有答案