Ionic Google Map Marker不会出现在Android设备中,但会出现在浏览器中

时间:2018-03-07 17:21:44

标签: android google-maps ionic-framework ionic3 google-maps-markers

我正在使用Ionic 3.我尝试在浏览器中运行我的应用程序,可以看到标记。当我在我的Android设备中运行它时,只标记了当前位置。任何答案为什么它没有在我的Android设备中找到?它在我的浏览器中完美运行。

displayGoogleMap() {


//get current location
this.geolocation.getCurrentPosition().then((resp) => {


  let latLng = new google.maps.LatLng(resp.coords.latitude, resp.coords.longitude);

  let mapOptions = {
    center: latLng,
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  this.map = new google.maps.Map(this.mapContainer.nativeElement, mapOptions);
  let marker = new google.maps.Marker({
    map: this.map,
    animation: google.maps.Animation.DROP,
    position: latLng
  });
  this.addInfoWindow(marker, 'Current Location');


}).catch((error) => {
  console.log('Error getting location', error);
});

} 我的displayGoogleMap()有效,但是当我添加多个标记时,它就不会出现。

addMarkersToMap(bank){

  console.log('bank: '+bank['id']+'lat: '+bank['address']['latitude']+' longi: '+bank['address']['longitude']);

  let position = new google.maps.LatLng(bank['address']['latitude'], bank['address']['longitude']);

  let mapOptions = {
    center: position,
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  this.map = new google.maps.Map(this.mapContainer.nativeElement, mapOptions);
  let marker = new google.maps.Marker({
    map: this.map,
    animation: google.maps.Animation.DROP,
    position: position
  });
  this.addInfoWindow(marker, bank['institution']);

}

addInfoWindow(marker,content){     让infoWindow = new google.maps.InfoWindow({       内容:内容     });     google.maps.event.addListener(marker,' click',()=> {       infoWindow.open(this.map,marker);     });   }

retrieveBloodBanks(){

var secret='aaaaaaaaaaaa';

  // return new Promise(resolve => {

  this.http.get('http://asdfghjk.aaa.aa.aa/api/institutions?secret='+secret)
    .map(res => res.json())
    .subscribe(data => {

      this.bankList = data;
      console.log( 'rtvr bank:  '+this.bankList);

      for (let bank of this.bankList['institutions']) {
          console.log(bank['id']);
          this.addMarkersToMap(bank);
      }

    });
  // });

} 如果你能帮助我,你对我的论文有很大的帮助。

1 个答案:

答案 0 :(得分:0)

您需要在addMarkersToMap()函数中删除map选项,

addMarkersToMap(bank) {

  console.log('bank: '+bank['id']+'lat: '+bank['address']['latitude']+' longi: '+bank['address']['longitude']);

  let position = new google.maps.LatLng(bank['address']['latitude'], bank['address']['longitude']);

  let marker = new google.maps.Marker({
    map: this.map,
    animation: google.maps.Animation.DROP,
    position: position
  });

  this.addInfoWindow(marker, bank['institution']);
}