安卓网页视图位置重定向

Android webview location redirect

本文关键字:位置 重定向 视图 网页      更新时间:2023-09-26

在我的应用程序中,我正在尝试获取设备的位置。如果应用程序上的位置服务工作正常。但是,如果位置服务在Android中,我希望应用程序显示一条消息,指出位置服务已关闭并提示输入地址。我的代码是

if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(init_pos,showerror);
        }
        else {
            window.open("Location.aspx", '_self', location = true);
        }
        function showerror(error) {
            switch (error.code) {
                case error.PERMISSION_DENIED:
                    window.open("Location.aspx", '_self', location = true);
                break;
                case error.POSITION_UNAVAILABLE:
                    window.open("Location.aspx", '_self', location = true);
                break;
                case error.TIMEOUT:
                    window.open("Location.aspx", '_self', location = true);
                break;
                case error.UNKNOWN_ERROR:
                    window.open("Location.aspx", '_self', location = true);
                break;
            }
        }
    }
    function init_pos(position) {
        lat = position.coords.latitude;
        long = position.coords.longitude;
        window.open("home1.aspx?lat=" + lat + "&lng=" + long, '_self', location = true);
    }

此代码在本地计算机 chrome 中工作,但在 android 设备中不起作用。

如果您想检查您的安卓设备的GPS是否已启用,那么您可以使用以下代码片段。

private LocationManager locManager;
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//GPS enabled       }
else
{
//GPS not enabled
}

而且我无法从发布的代码中获取任何内容来获取当前位置。为了更好地理解,请查看此 http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/