【问题标题】:Ionic Google Map Marker won't appear in android device but appears in the browserIonic Google Map Marker 不会出现在 android 设备中,但会出现在浏览器中
【发布时间】:2018-03-07 17:21:43
【问题描述】:

我正在使用 Ionic 3。我尝试在浏览器中运行我的应用程序,并且可以看到标记。当我在我的 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(银行) {

  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(标记,内容){ 让 infoWindow = new google.maps.InfoWindow({ 内容:内容 }); google.maps.event.addListener(marker, 'click', () => { infoWindow.open(this.map, marker); }); }

检索血库(){

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);
      }

    });
  // });

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

【问题讨论】:

  • 你有什么错误吗?

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


【解决方案1】:

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

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']);
}

【讨论】:

    猜你喜欢
    • 2010-12-03
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2021-04-25
    • 1970-01-01
    • 2019-05-14
    相关资源
    最近更新 更多