IOS上的位置不适用于离子2中的地理位置

问题描述 投票:0回答:2

我正在尝试在构建离子的构建时执行此操作,但该位置在IOS上,并且不适用于离子2应用程序中的地理位置。

我已经安装了离子cordova插件添加cordova-plugin-geolocation和

在Android设备中,它在定位服务时工作。当位置服务无法正常工作时。在iOS设备中,两种情况都不起作用。需要一些帮助!!

import { Geolocation } from '@ionic-native/geolocation';

在提供商中,我提到了地理定位;在home.ts我导入了Geolocation。

要获取当前位置,我已编写以下代码

getCurrentLocation(){    
    this.geolocation.getCurrentPosition().then((position) => {
        let loc = {
          placeId: null,
          name:null,
          lat:null,
          long:null,
        }

        var lat = position.coords.latitude;
        var lng = position.coords.longitude;
        var latlng = new google.maps.LatLng(lat, lng);
        var geocoder = geocoder = new google.maps.Geocoder();
}
javascript html ios angular ionic2
2个回答
3
投票

如果IOS上的位置不适用于地理位置

从iOS 10开始,必须在info.plist中添加NSLocationWhenInUseUsageDescription条目。

NSLocationWhenInUseUsageDescription描述了应用访问用户位置的原因。

当系统提示用户允许访问时,此字符串将显示为对话框的一部分。

要添加此条目,您可以在插件安装上传递变量GEOLOCATION_USAGE_DESCRIPTION。

示例:cordova插件添加cordova-plugin-geolocation - 变量GEOLOCATION_USAGE_DESCRIPTION =“您的使用信息”

如果您没有传递变量,插件将添加一个空字符串作为值。

要解决您的问题,请尝试:卸载插件:cordova插件删除cordova-plugin-geolocation重新安装:

cordova插件添加cordova-plugin-geolocation - 变量GEOLOCATION_USAGE_DESCRIPTION =“my_project想要使用你的位置”

平台/ IOS /(项目)/(项目)/project.info.plist

这将自动在info.plist文件中添加条目


1
投票

您也可以手动编辑platform / ios / {project} / {project} /project.info.plist文件并添加以下行

 <key>NSLocationWhenInUseUsageDescription</key>
 <string>Location is needed because [your reason]</string>
© www.soinside.com 2019 - 2024. All rights reserved.