cordova - 地理定位在 Cordova Android 模拟器中不起作用

标签 cordova visual-studio-2013 geolocation phonegap-plugins cordova-plugins

我正在使用 Visual Studio Cordova 工具来创建应用程序。我正在使用 HTML5 的地理定位来获取用户位置。

当我在ripple naxus-galaxy中执行它时,它工作正常,但是当我在android模拟器中运行它时,它根本不起作用。它在顶部栏上显示了 GPS 系统。但之后什么也没有发生。我还添加了 geoLocation 插件。

我的代码是,

    // For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkID=397704
// To debug code on page load in Ripple or on Android devices/emulators: launch your app, set breakpoints, 
// and then run "window.location.reload()" in the JavaScript Console.
(function () {
    "use strict";

    document.addEventListener('deviceready', onDeviceReady.bind(this), false);

    function onDeviceReady() {
        // Handle the Cordova pause and resume events
        document.addEventListener('pause', onPause.bind(this), false);
        document.addEventListener('resume', onResume.bind(this), false);

        // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.

        var geo_options = {
            enableHighAccuracy: true,
            maximumAge: 50000,
            timeout: 30000
        };

        var mapWatchId = navigator.geolocation.watchPosition(onSuccess, onError, geo_options);
        alert("Watch" + mapWatchId);
    };


    function onSuccess(position) {
        alert("onSuccess = " + JSON.stringify(position));
    };

    function onError(error) {
        alert("Error");
        switch (error.code) {
            case error.PERMISSION_DENIED:
                alert("Please share your location with us to move ahead.");
                break;
            case error.POSITION_UNAVAILABLE:
                alert("Location information is not available, Check your internet connection.");
                break;
            case error.TIMEOUT:
                alert("The request to get user location timed out.");
                break;
            case error.UNKNOWN_ERROR:
                alert("We are not able to fetch your location details.");
                break;
        }
    };
    function onPause() {
        // TODO: This application has been suspended. Save application state here.
    };

    function onResume() {
        // TODO: This application has been reactivated. Restore application state here.
    };
})();

我的配置文件是,

<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps" id="io.cordova.Geo" version="1.0.0.0" xmlns="http://www.w3.org/ns/widgets">
  <name>Geo</name>
  <description>A blank project that uses Apache Cordova to help you build an app that targets multiple mobile platforms: Android, iOS, Windows, and Windows Phone.</description>
  <author href="http://cordova.io" email="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e98d8c9fa98a869b8d869f88c78899888a818cc7869b8e" rel="noreferrer noopener nofollow">[email protected]</a>">Apache Cordova Team </author>
  <content src="index.html" />
  <access origin="*" />
  <preference name="SplashScreen" value="screen" />
  <preference name="windows-target-version" value="8.0" />
  <preference name="windows-phone-target-version" value="8.1" />
  <vs:plugin name="org.apache.cordova.geolocation" version="0.3.10" />
  <vs:platformSpecificValues />
</widget>

甚至,它根本没有调用 gMap() 函数,因为警报本身还没有到来。

请检查上面的代码并告诉我必要的更改。

谢谢。

最佳答案

您无法在 Android 模拟器内测试地理定位模式,推送通知也是如此。您需要在真实的移动设备中进行测试。

关于cordova - 地理定位在 Cordova Android 模拟器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28778209/

相关文章:

git - visual studio 2013如何记住远程git/tfs仓库和本地路径之间的映射?

ios - 从承运人处获取位置而不是纬度/经度

ios - verseGeocodeLocationCompletionHandler 失败并显示 "[TNSDictionaryAdapter coordinate]: unrecognized selector sent to instance"

iphone - PGPlugin 类 PGBatteryLevelPlugin (pluginName : com.phonegap.battery) 不存在?

cordova - Meteor appcache 可用于为 phonegap 捆绑应用程序吗?

c# - Visual Studio 2013 不发现单元测试

c++ - 如何从strftime捕获格式错误?

java - 除非 GPS 开启,否则融合位置提供程序无法获取位置

javascript - 如何重定向到phonegap iphone中的本地html页面

android - 使用 PhoneGap 在 Android 中删除缓存