简体   繁体   English

Android Webview位置重定向

[英]Android webview location redirect

In my app I am trying to get the location of the device. 在我的应用程序中,我试图获取设备的位置。 If location services are on the app works fine. 如果位置服务在应用程序上正常运行。 But if the location services are of in android I want the app to show a message that location services are off and prompt to enter address. 但是,如果位置服务在android中,则我希望该应用显示一条消息,指出位置服务已关闭并提示输入地址。 My code is 我的代码是

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);

    }

This code is working in local computers chrome but not in android device. 此代码在本地计算机Chrome中有效,但在android设备中不起作用。

If you want to check whether your android devices's GPS enabled or not then you can use below snippet. 如果要检查您的android设备的GPS是否已启用,则可以使用以下代码段。

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

And i can't get anything out of the posted code to get current location. 而且我无法从发布的代码中获取任何信息来获取当前位置。 For better understanding have a look at this http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ 为了更好的理解,请查看此http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/

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

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