菜鸟教程小白 发表于 2022-12-13 00:19:14

ios - $cordova.geolocation 未获取 IOS 中当前位置的经度和纬度


                                            <p><p>我在 ionic 应用程序中使用了 $cordovaGeolocation.getCurrentPosition。它在 android 和 web 中正常工作并正确获取位置。但在 xcode 模拟器中它不起作用并且无法获取纬度和经度。并且无法获取经度和纬度。</p>

<pre><code>var posOptions = {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
};


$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {

$scope.Lat= position.coords.latitude;
$scope.Long = position.coords.longitude;

console.log(&#39;lat:&#39;, $scope.Lat);
console.log(&#39;long:&#39;, $scope.Long);   
}, function(err) {
console.log(err);
});
</code></pre>

<p>我已将此代码放在 <code>.run</code> 函数 <code>app.js</code> 文件中。</p>

<pre><code>document.addEventListener(&#34;deviceready&#34;, onDeviceReady, false);
function onDeviceReady() {
    console.log(&#34;corodova.geolocation works well&#34;);
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在 iPhone 模拟器中,您可以模拟位置。</p>

<p>你需要去调试 -> 位置 -> 自定义位置</p>

<p> <a href="/image/Fxd0M.png" rel="noreferrer noopener nofollow"><img src="/image/Fxd0M.png" alt="location"/></a> </p>

<p>您可以在对话框中添加自定义纬度,然后按确定。</p>

<p> <a href="/image/jlUVG.png" rel="noreferrer noopener nofollow"><img src="/image/jlUVG.png" alt="enter image description here"/></a> </p>

<p>您还可以从 Xcode 模拟位置。</p>

<p>为此,您需要运行一个应用程序,在日志区域上方,您将看到如下图所示的导航按钮并从列表中选择城市。</p>

<p> <a href="/image/b1qTe.png" rel="noreferrer noopener nofollow"><img src="/image/b1qTe.png" alt="enter image description here"/></a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - $cordova.geolocation 未获取 IOS 中当前位置的经度和纬度,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43014878/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43014878/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - $cordova.geolocation 未获取 IOS 中当前位置的经度和纬度