Angular 因此,类型Void-Ionic上不存在该属性

Angular 因此,类型Void-Ionic上不存在该属性,angular,google-maps,typescript,ionic-framework,ionic3,Angular,Google Maps,Typescript,Ionic Framework,Ionic3,单击按钮时在加载标记时遇到问题。因为现在我正试图在我附近找到健身房的位置。现在,单击按钮时,地图将加载到我的位置,但不会显示任何标记。我还得到一个错误,即我的IonViewDidLoad gyms.html <ion-header> <ion-navbar> <ion-title>Gyms Nearby</ion-title> </ion-navbar> </ion-header> <ion-con

单击按钮时在加载标记时遇到问题。因为现在我正试图在我附近找到健身房的位置。现在,单击按钮时,地图将加载到我的位置,但不会显示任何标记。我还得到一个错误,即我的
IonViewDidLoad

gyms.html

<ion-header>

  <ion-navbar>
    <ion-title>Gyms Nearby</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <ion-buttons start>
    <button ion-button round full (click)="gymMap()">Find Gyms Near Me</button>
  </ion-buttons>

  <div #map id="map"> </div>

  <div id="resultList">
      <ion-list>

        <ion-card>
           <ion-item ng-if = "places" >
           Places Found: {{places?.length}}
          </ion-item>
         </ion-card>  

        <ion-card id="result"> </ion-card>
          <button ion-item *ngFor = "let place of places; let i = index">
           {{place.name}} + <br/> {{place.vicinity}} <br /> Average Rating: {{place.rating}}
          </button>
        </ion-list>
  </div>

</ion-content>

附近的健身房
在我附近找健身房
找到的位置:{Places?.length}
{{place.name}+
{{place.neighborary}
平均评分:{{place.Rating}
健身房

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';

declare var google;


@Component({
  selector: 'page-gyms',
  templateUrl: 'gyms.html',
})
export class GymsPage {
  map: any;
  places: Array<any>;  

  constructor(public navCtrl: NavController, public navParams: NavParams, public geolocation:Geolocation) {
  }

  ionViewDidLoad() {
    this.gymMap().then((results : Array <any>)=>{
      for (let i=0; i< results.length; i++){
        this.createMarker(results[i]);
      }
      this.places = results;
    }, (status)=>console.log(status));
  }

  gymMap(){
    this.geolocation.getCurrentPosition().then((position) =>{
      let currentLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

      let mapOptions = {
        zoom: 12,
        center: currentLocation,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      this.map = new google.maps.Map(document.getElementById("map"),mapOptions);

      let service = new google.maps.places.PlacesService(this.map);
      let request = {
        location : currentLocation,
        radius : '10000',
        rankBy : google.maps.places.DISTANCE,
        type: ['gym'],
      };

      return new Promise((resolve,reject) =>{
        service.nearbySearch(request,(results,status)=>{
          if (status == google.maps.places.PlacesServiceStatus.OK){
            resolve(results);
          }else{
            reject(results);
          }
        });
      }); 

    }); 

  }//end of gymMap

  createMarker(place){
    let marker = new google.maps.Marker({
      map: this.map,
      animation: google.maps.Animation.DROP,
      position: place.geometry.location,
      title: place.name,
    });

    google.maps.event.addListener(marker, 'click', ()=>{
      let infowindow = new google.maps.InfoWindow({
        content: place.name 
      });
      infowindow.open(this.map,marker);
    })
  }//end of createMarker


}//end of GymsPage
从'@angular/core'导入{Component};
从“离子角度”导入{NavController,NavParams};
从'@ionic native/Geolocation'导入{Geolocation};
谷歌公司;
@组成部分({
选择器:“页面健身房”,
templateUrl:'gyms.html',
})
出口级体操{
地图:任何;
地点:阵列;
构造函数(公共navCtrl:NavController、公共navParams:navParams、公共地理位置:地理位置){
}
ionViewDidLoad(){
this.gymMap().then((结果:数组)=>{
for(设i=0;iconsole.log(状态));
}
gymMap(){
this.geolocation.getCurrentPosition()。然后((位置)=>{
让currentLocation=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
让mapOptions={
缩放:12,
中心:当前位置,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
this.map=new google.maps.map(document.getElementById(“map”)、mapOptions);
让service=newgoogle.maps.places.PlacesService(this.map);
让请求={
位置:当前位置,
半径:“10000”,
rankBy:google.maps.places.DISTANCE,
类型:[“健身房”],
};
返回新承诺((解决、拒绝)=>{
service.nearbySearch(请求,(结果,状态)=>{
if(status==google.maps.places.PlacesServiceStatus.OK){
决心(结果);
}否则{
拒绝(结果);
}
});
}); 
}); 
}//地图的结尾
创建标记(位置){
让marker=new google.maps.marker({
map:this.map,
动画:google.maps.animation.DROP,
位置:place.geometry.location,
标题:place.name,
});
google.maps.event.addListener(标记,'click',()=>{
让infowindow=new google.maps.infowindow({
内容:place.name
});
infowindow.open(this.map,marker);
})
}//创建标记的结束
}//体操结束

您需要使用如下所示的
胖箭头功能

1地点:

第二名:


您需要使用如下所示的
fat arrow
函数

1地点:

第二名:


我做了更改,但“then”错误仍在发生,现在this.gymma未定义@sampath您能显示您的最新代码吗?您是在设备上测试还是在测试?希望您使用的是本机插件。在设备上进行测试?localhost ionic Lab您必须在真实设备上进行测试,因为这是本机插件。我做了更改,但“then”错误仍然存在,现在此.gymma未定义@Sampath。您能显示最新代码吗?您是在设备上测试还是在测试?希望您使用的是本机插件。在设备上测试?localhost ionic Lab您必须在真实设备上测试,因为这是本机插件。
return new Promise((resolve,reject)=>{
        service.nearbySearch(request, (results,status)=>{
          if (status == google.maps.places.PlacesServiceStatus.OK){
            resolve(results);
          }else{
            reject(results);
          }
        });
      });
google.maps.event.addListener(marker, 'click', ()=>{
      let infowindow = new google.maps.InfoWindow({
        content: place.name 
      });
      infowindow.open(this.map,marker);
    })