本文介绍了检查用户设备的GPS是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个使用jQuery Mobile和PHP的应用程序。我没有使用Phonegap或其他框架。我需要找到用户的 geolocation
。如果用户设备的GPS关闭,那么我无法获得一个位置。现在我需要找到用户设备的GPS已打开或关闭。
I am developing an app using jQuery Mobile with PHP. I am not using Phonegap or other frameworks. I need to find user's geolocation
. If user device's GPS is off, then I cant get a location. now I need to find user device's GPS is on or off.
这是我现在使用的。
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var lat=position.coords.latitude;
var long=position.coords.longitude;
}
推荐答案
load
You can call this function on load
// Function to get location
function getLocation(){
navigator.geolocation.getCurrentPosition(function (pos) {
var lat = pos.coords.latitude;
var lng = pos.coords.longitude;
if (lat == null) {
alert("GPS not activated!");
}
else{
alert("Latitude: "+ lat + " , Longitude: " + lng );
}
});
}
这篇关于检查用户设备的GPS是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!