首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AGM地图不显示标记

AGM地图不显示标记
EN

Stack Overflow用户
提问于 2018-04-17 12:06:32
回答 1查看 2.1K关注 0票数 1

我试图使用AGM (https://angular-maps.com/)在一个角4应用程序作为概念的证明,基本上从api得到一个json和动态显示在AGM地图中的位置。

不幸的是,api中的JSON似乎没有更新地图。

你知道为什么吗?

提前谢谢你。

代码语言:javascript
复制
export class HomeComponent implements OnInit {

  public PageTitle: string = 'Location';
  public latitude: number = 50.984795;
  public longtitude: number = 8.9483832;
  public zoom: number = 7;

  public CompanyMarkers: marker[]  ;

  public localState = { value: '' };

  constructor(
    public appState: AppState,
    public title: Title,
    private http: HttpClient,

  ) {  

}

getLocations() {
  return this.http.get<marker[]>('api')
  .map(res => res);
}

  public ngOnInit() {
    console.log('hello `Home` component');

     this.getLocations().subscribe(data => {
      this.CompanyMarkers = data;
      console.log('init');
      console.log(this.CompanyMarkers);

    });

  }

}

interface marker {
CompanyAccountId?:string;
companyName?:string;
latitude?: number;
longtitude?: number;
}


<agm-map 
        [latitude]="latitude" 
        [longitude]="longtitude" 
        [zoom]="zoom"
        [disableDefaultUI]="false"
        [zoomControl]="false">

    <agm-marker 
    *ngFor="let m of CompanyMarkers;let i = index;"  
    [iconUrl]="'/assets/icon/icon-company.png'" 
    [latitude]="m.latitude" 
    [longitude]="m.longtitude">
    <agm-info-window>
        <strong>{{m.companyName}} </strong>
    </agm-info-window>
</agm-marker>     
      </agm-map>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-17 13:22:08

尝尝这个

代码语言:javascript
复制
<agm-marker 
    *ngFor="let m of CompanyMarkers;let i = index;"  
    [iconUrl]="'/assets/icon/icon-company.png'" 
    [position]="[m.latitude, m.longitude]">
    <agm-info-window>
        <strong>{{m.companyName}} </strong>
    </agm-info-window>
</agm-marker>     

还要检查你的经度拼写。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49877697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档