本文档中的地理位置政策已禁用地理位置定位

时间:2018-08-07 02:11:02

标签: javascript angular google-maps ionic-framework ionic3

在我的离子应用程序中,我正在尝试使用Google地图。当我使用下面的代码时,它确实在页面上显示了地图。

let latLng = new google.maps.LatLng(-34.9290, 138.6010);

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

this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

但是当我使用下面的代码时,我得到了

  

Geolocation has been disabled in this document by Feature Policy错误。

this.geolocation.getCurrentPosition().then((position) => {

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

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

  this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

}, (err) => {
  console.log(err);
});

0 个答案:

没有答案
相关问题