Having feature policy issue with geolocation using

2019-08-27 14:38发布

问题:

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" />