我试图访问位置视图到位置的值和离子和'我得到== [对象位置]

时间:2018-06-09 03:59:52

标签: ionic-framework geolocation

我正在使用谷歌地图API,地图显示正确但我无法打印位置值,它继续在浏览器中打印[对象位置]离子 我帮助解决了这个问题,被困在这里几个小时

`

  

导入{Component,ViewChild,ElementRef}来自' @ angular / core&#39 ;;       从' ionic-angular';

导入{NavController}
declare var google;
let map: any;
let infowindow: any;
let options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  @ViewChild('map') mapElement: ElementRef;
  constructor(public navCtrl: NavController) {
    this.initMap();
  }

  initMap() {
       navigator.geolocation.getCurrentPosition((location) => {
      //console.log(location);
      var positionOption = {timeout: 10000, enableHighAccuracy: true};


      alert(location);
      map = new google.maps.Map(this.mapElement.nativeElement, {
        center: {lat: location.coords.latitude, lng: location.coords.longitude, },
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });

      infowindow = new google.maps.InfoWindow();
      var service = new google.maps.places.PlacesService(map);
      service.nearbySearch({
        location: {lat: location.coords.latitude, lng: location.coords.longitude},
        radius: 1000,
        type: ['store']
      }, (results,status) => {
        if (status === google.maps.places.PlacesServiceStatus.OK) {
          for (var i = 0; i < results.length; i++) {
            this.createMarker(results[i]);
          }
        }
      });
    }, (error) => {
      console.log(error);
    }, options);
    //var myplace = {lat: -33.8665, lng: 151.1956};
  }

  createMarker(place) {
    var placeLoc = place.geometry.location;
    var marker = new google.maps.Marker({
      map: map,
      position: placeLoc
    });

    google.maps.event.addListener(marker, 'click', function() {
      infowindow.setContent(place.name);
      infowindow.open(map, this);
    });
  }
}

`

  

块引用

[对象位置]

> Blockquote

0 个答案:

没有答案