简体   繁体   English

HTML5地理位置-不适用于Android

[英]HTML5 geolocation - not working on Android

The project I'm working on uses smartphones with Android (can't tell what version but it's recent) to find the user's current position. 我正在研究的项目使用具有Android的智能手机(无法告诉您最新版本)来查找用户的当前位置。 However, at the moment, it brings up the "share current position" allow/reject question, but then does nothing. 但是,此刻,它提出了“共享当前位置”允许/拒绝问题,但是什么也不做。 If you leave it on that then the page in the background reloads after a bit, and if you allow it then it reloads in any case. 如果将其保留在该页面上,则稍后会重新加载后台页面;如果允许,则无论如何都将重新加载。 It should bring up the location in a message prompt. 它应该在消息提示中显示该位置。

I will point out that this works on an iPhone I've had access to, and in IE10 (I think it is). 我要指出的是,这在我可以使用的iPhone和IE10(我认为是)中都可以使用。

<asp:Button ID="btnLocate" Text="Loc" OnClientClick="return GetLocation()" runat="server" />

<script type="text/javascript">

            function GetLocation()
            {
                if (navigator.geolocation)
                {
                    navigator.geolocation.getCurrentPosition(ShowPosition, ShowError, { enableHighAccuracy: true, timeout: 31000, maximumAge: 90000 });
                }
                else{alert("Geolocation is not supported by this browser.");}
            }
            function ShowPosition(position)
            {
                alert(position.coords.latitude + "," + position.coords.longitude);
                return false;
            }
            function ShowError(error)
            {
                switch(error.code) 
                {
                    case error.PERMISSION_DENIED:
                        alert("User denied the request for Geolocation.");
                        break;
                    case error.POSITION_UNAVAILABLE:
                        alert("Location information is unavailable.");
                        break;
                    case error.TIMEOUT:
                        alert("The request to get user location timed out.");
                        break;
                    case error.UNKNOWN_ERROR:
                        alert("An unknown error occurred.");
                        break;
                }
            }
        </script>

I should also mention that GPS is enabled and Google Maps is able to find the location just-about instantly. 我还应该提到GPS已启用,并且Google Maps能够立即找到该位置。

The issue with his code is that the button was acting as a form submit action. 他的代码的问题在于该按钮充当了表单提交操作。 So even though the browser paused to prompt for the OK, as soon as it was out of the way a form submission was fired. 因此,即使浏览器暂停提示输入“确定”,也不会立即触发表单提交。 Adding return false to the end of handler should correct it (basically saying, "Dont submit this form"). 添加返回false,处理程序结束应该纠正它(基本上是说,“不要提交此表”)。 I don't know ASP.Net very well so that may not be it exactly. 我不太了解ASP.Net,因此可能不是完全正确。

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

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