简体   繁体   English

地理位置可在网络浏览器上使用,但不能在android手机浏览器上使用

[英]geolocation working on web browser but not on android phone browser

i have page with button, when clicked shows an alert with latitude and longitude. 我有带按钮的页面,单击该按钮会显示带有经度和纬度的警报。 It works on Chrome on my laptop but when i tried with my android mobile, the page is showing but the alert is not. 它可以在笔记本电脑上的Chrome上运行,但是当我尝试使用android移动设备时,页面会显示,但警报却没有。 I have tried changing watchPosition with getCurrentPosition, but no change. 我尝试使用getCurrentPosition更改watchPosition,但没有更改。
In an attempt to solve it, i have put up an alert checkpoint and i have found out that the function success() is getting called in laptop browser but not in android browser, not even the function error() is being called. 为了解决这个问题,我建立了一个警报检查点,发现在笔记本浏览器中调用了Success()函数,但在android浏览器中未调用,甚至没有调用error()函数。 please help. 请帮忙。

<html>
<head><title>Geolocation</title></head>
<body onload="getLocation();">
<input type="button" id="btnSearch" value="Search" onclick="btn_Click();"/>

<script>
    var pos;
    function btn_Click() {
        alert("Alert");
        //alert('Lat: ' + pos.coords.latitude + ' ' + 'Lon: ' + pos.coords.longitude);
    }

    function getLocation() {
        alert("doSomething");
        if (navigator.geolocation) {
            alert("navigator.geolocation");
            navigator.geolocation.getCurrentPosition(success,error,options);
            function success(position) {
                alert("success");
                pos = position;
            }
            function error(err) {
                alert("Error");
            };
            var options = {
                enableHighAccuracy: true,
                timeout: 5000,
                maximumAge: 0
            };
        } else {
            alert("I'm sorry, but geolocation services are not supported by your browser.");
        }

    }
</script>
</body>
</html>

i have even tried google gears, Now the gps sign is coming up on android but the location is still not showing.... 我什至尝试了Google Gears,现在Android上出现了gps标志,但是位置仍然没有显示。

<html>
<head><title>Javascript geo sample</title>
<script src="geo-min.js" type="text/javascript" charset="utf-8"></script>
</head> 
<body>
<b>Javascript geo sample</b>
<script>
    var pos;
    if (geo_position_js.init()) {
        geo_position_js.watchPosition(success_callback, error_callback, { enableHighAccuracy: true });
    }
    else {
        alert("Functionality not available");
    }

    function success_callback(p) {
        pos = p;
        alert('lat=' + p.coords.latitude.toFixed(2) + ';lon=' + p.coords.longitude.toFixed(2));
    }

    function error_callback(p) {
        alert('error=' + p.message);
    }

    function ChangeLabel() {
        document.getElementById("Label1").innerHTML =pos.coords.latitude;
    }
</script>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<input type="button" ID="Button1" value="Button" onclick="ChangeLabel()"/>
</body>
</html>

Your code seems to be working perfectly fine. 您的代码似乎运行得很好。

For the Geo-location to work on an Android OS, you need to give a few permissions in the AndroidManifest.xml file, namely: 为了使地理位置能够在Android OS上运行,您需要在AndroidManifest.xml文件中提供一些权限,即:

Uses Permissions:- 使用权限:

ACCESS_LOCATION_EXTRA_COMMANDS
ACCESS_COARSE_LOCATION
ACCESS_FINE_LOCATION

If you want the Geo-location functionality to work on all Android version, you also need to add: 如果要让地理位置功能在所有Android版本上都可以使用,则还需要添加:

WRITE_EXTERNAL_STORAGE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM