【发布时间】:2019-04-03 17:59:40
【问题描述】:
我目前正在 Laravel 中进行我的项目。我需要获取有关用户的信息(主要是他的位置),以使我的应用程序能够顺利运行;所以我研究了一段时间,了解了地理定位。我有以下代码可以找到用户的位置:
var location;
var latitude;
var longitude;
function findLocation() {
var geoSuccess = function(position) {
location = position;
latitude = location.coords.latitude;
longitude = location.coords.longitude;
console.log("Latitude is " + location.coords.latitude);
console.log("Longitude is " + location.coords.longitude);
};
navigator.geolocation.getCurrentPosition(geoSuccess);
};
问题是,用户需要提供他的位置才能注册他的帐户。因此,当用户禁止位置权限时,我想通知用户提供位置以继续。但我不知道该怎么做。我想做的是:
if(error){
console.log("You need to provide your location!");
// I will do a bunch of stuffs here
}
那么,我该怎么做呢?任何帮助表示赞赏。
注意:地理位置代码取自 W3Schools.com
【问题讨论】:
标签: javascript php callback geolocation