Having feature policy issue with geolocation using ionic

爱⌒轻易说出口 提交于 2019-12-13 02:56:05

问题


I am using Google maps on my ionic project using following code.

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

with above code, I am getting this error.

Geolocation has been disabled in this document by Feature Policy

Any idea how can I resolve this issue?

Thanks


回答1:


It is because Geolocation API isemoved from unsecured origins. You can solve it by adding appropriate permissions. On Android platform, open your project, search for AndroidManifest.xml and add these lines:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />


来源:https://stackoverflow.com/questions/51734268/having-feature-policy-issue-with-geolocation-using-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!