0

我创建了要检查手机位置的 Adroid 应用程序。我启动了模拟器安装应用程序,每次我想检查它都失败了。模拟器是问题(因为它不是真正的手机)还是我没有正确执行。

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
                <title>Hello World</title>
        <script type="text/javascript" src="cordova-2.1.0.js"></script>
        <script text="text/javascript">
        function startUp(){
            document.getElementById("H1").innerHTML = "Checking your location...";
           document.addEventListener("deviceready", onDeviceReady, false)
        }
        function onDeviceReady() {
        navigator.geolocation.getCurrentPosition(onSuccess, onError);
    }

    // onSuccess Geolocation
    //
    function onSuccess(position) {
        var element = document.getElementById('location');
        element.innerHTML = 'Latitude: '           + position.coords.latitude              + '<br />' +
                            'Longitude: '          + position.coords.longitude             + '<br />' +
                            'Altitude: '           + position.coords.altitude              + '<br />';
                            document.getElementById("H1").innerHTML = "";
    }

    // onError Callback receives a PositionError object
    //
    function onError(error) {
        document.getElementById("H1").innerHTML = "Fail to check your location.";
    }

        </script>
    </head>
    <body style="margin:0px;" onload="startUp()" bgcolor="#000">
        <div class="app" style="background-color:#4D4D4D">
            <font color="#FF9900" size="2"><h1 id="H1" style="font-family:courier new;"></h1></font>
            <p id="location"></p>
        </div>



    </body>
</html>

HTML5 文件和 config.xml

<?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "com.park.manager"
        versionCode="10" 
        version   = "0.1.9">
    <name>ParkingManager</name>
    <description>
        A system, which manages parking side areas.
    </description>
    <author href="" email="">
        Parking Side Manager Team
    </author>
    <preference name="phonegap-version" value="2.1.0" />
    <preference name="orientation" value="landscape" />
    <preference name="target-device" value="universal" />
    <preference name="fullscreen" value="true" />
    <preference name="android-installLocation" value="auto" />
    <icon src="icon.png" />
    <gap:splash src="splash.png" />
    <feature name="http://api.phonegap.com/1.0/geolocation"/>
    <feature name="http://api.phonegap.com/1.0/network"/>

</widget>
4

3 回答 3

0

上次我使用 PhoneGap 时,清单文件中已经有正确的权限。

您很可能需要为模拟器提供模拟数据。 http://developer.android.com/guide/topics/location/strategies.html#MockData

于 2012-11-07T20:24:50.403 回答
0

它是模拟器,你需要一部真正的手机,因为模拟器很痛苦,因为你知道如何才能正常工作。你的 Javascript 和 html 都很好。

于 2013-04-01T21:14:37.123 回答
0

确保在清单 XML 中添加粗略和精细位置的权限。

电话差距有其好处,但它不会解决您的一些主要问题,例如必须手动执行清单。如果您在知道如何添加这些权限之前使用 java 制作了您的应用程序。如果不使用检查如何做到这一点。权限

除了你的cordova geolaction调用是正确的之外,我之前从他们的例子中使用过它。

于 2012-11-07T20:22:36.727 回答