谷歌地图标记可以在浏览器中看到,但不能在Android中看到

时间:2018-03-07 10:46:55

标签: android angularjs google-maps ionic3 google-geolocation

我正在使用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){
    let infoWindow = new google.maps.InfoWindow({
      content: content
    });
    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)

让mapOptions = {          center:{lat:lat,lng:lng},         zoom:15,         mapTypeId:google.maps.MapTypeId.ROADMAP       };

尝试使用lat,而不是'new google.maps.LatLng'?