【发布时间】:2015-02-28 04:50:54
【问题描述】:
我正在使用 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="dev@cordova.apache.org">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() 函数,因为警报本身并没有到来。
请检查上面的代码并告诉我必要的更改。
谢谢。
【问题讨论】:
-
您正在使用“body.onload”事件而不是“deviceready”。正文加载了什么,与加载的cordova api无关。
-
在真实设备中测试它应该可以工作
标签: cordova visual-studio-2013 geolocation phonegap-plugins cordova-plugins