Php 是什么导致Safari在此代码中获取navigator.geolocation.getCurrentPosition失败?
第二次更新:由于没有修复Safari和其他一些奇怪的行为,我决定使用此选项为Safari用户创建所有新的无聊内容(基本上放弃Safari脚本) 原始问题:我可以在Safari以外的其他移动设备/浏览器中使用此功能。而在iphone上,它失败了,所以用!并在Safari桌面浏览器中进行了测试,出现了同样的问题,一旦我同意,就不会返回我的数据。这是我现在正在使用的代码块Php 是什么导致Safari在此代码中获取navigator.geolocation.getCurrentPosition失败?,php,javascript,ios,mobile,geolocation,Php,Javascript,Ios,Mobile,Geolocation,第二次更新:由于没有修复Safari和其他一些奇怪的行为,我决定使用此选项为Safari用户创建所有新的无聊内容(基本上放弃Safari脚本) 原始问题:我可以在Safari以外的其他移动设备/浏览器中使用此功能。而在iphone上,它失败了,所以用!并在Safari桌面浏览器中进行了测试,出现了同样的问题,一旦我同意,就不会返回我的数据。这是我现在正在使用的代码块 <?php if(!($detect->isMobile())) { ?> $(function() {
<?php if(!($detect->isMobile())) { ?>
$(function() {
if(navigator && navigator.geolocation) {
var fallback = setTimeout(function() { fail('10 seconds expired'); }, 10000);
navigator.geolocation.getCurrentPosition(
function (pos) {
clearTimeout(fallback);
var point = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
new google.maps.Geocoder().geocode({'latLng': point}, function (res, status) {
if(status == google.maps.GeocoderStatus.OK && typeof res[0] !== 'undefined') {
var zip = res[0].formatted_address.match(/,\s\w{2}\s(\d{5})/);
if(zip) {
var zipcodepassed = zip[1];
$("#em").html(zipcodepassed);
var reps = reps_load;
var ads_repList_URLtoFullName = ads_repList_URLtoFullName_load;
var rek = ads_repList_URLtoFullName;
var rep = reps[zipcodepassed];
if (rep == undefined || rep == null || rep == "") {
$(function() {
$("#gotorep").remove();
$("#entersite").remove();
$("#entersite2").css({'display':'inline'});
});
}
var repname = rek[rep]; //i.e. shaner will be Shane Reaume in repname variable
$("#yourrep").html(repname);
$("a[href='http://devv.referadiabetic.com']").attr('href', 'http://devv.referadiabetic.com/' + rep);
}
}
});
}
);
}
});
$(函数(){
if(navigator&&navigator.geolocation){
var fallback=setTimeout(函数(){fail('10秒过期');},10000);
navigator.geolocation.getCurrentPosition(
功能(pos){
清除超时(回退);
var point=new google.maps.LatLng(pos.coords.lation,pos.coords.longitude);
新的google.maps.Geocoder().geocode({'latLng':point},函数(res,status){
if(status==google.maps.GeocoderStatus.OK&&typeof res[0]!==undefined'){
var zip=res[0]。格式化的_地址。匹配(/,\s\w{2}\s(\d{5})/);
如果(zip){
var zipcodepassed=zip[1];
$(“#em”).html(zipcodepassed);
var reps=reps_负载;
var ads_repList_urltoullname=ads_repList_urltoullname_load;
var rek=ads\u repList\u URLtoFullName;
var rep=reps[zipcodepassed];
如果(rep==未定义| | rep==空| | rep==“”){
$(函数(){
$(“#gotorep”).remove();
$(“#输入”).remove();
$(“#entresite2”).css({'display':'inline'});
});
}
var repname=rek[rep];//也就是说,shaner将是repname变量中的Shane Reaume
$(“#yourrep”).html(repname);
$(“a[href=”http://devv.referadiabetic.comattr('href','http://devv.referadiabetic.com/"代表",;
}
}
});
}
);
}
});
我已经有了一个退路,我使用IP地址来获取邮政编码,但由于移动设备的性质,我正在设置这些地址来执行这段代码。
setTimeout
期望第一个参数是某个代码字符串或函数调用。我相信它试图将失败
解析为字符串,并且。。。嗯。。。失败
setTimeout("function() fail('10 seconds expired');", 10000);
它发生在桌面Safari上,对吗?打开开发人员工具并在控制台运行时观察它,您可能会在那里看到错误。@Charles我在顶部分享了我的错误,现在正在研究这个问题,谢谢。根据,您应该能够将函数直接传递到setTimeout,而不会出现问题。你修改过的代码实际上只是返回一个函数。。。但是它并没有真正返回到任何地方,所以它基本上是不可操作的。这并不能阻止
fail
没有在setTimeout上下文中定义,当然,这是根本的问题。我同意,但Safari肯定存在fail
的问题。此时,我通常会查看它是否是保留字,但我已经知道它不是。@Charles I删除了回退,现在我没有收到错误,但它也不会返回位置。
<?php if(!($detect->isMobile())) { ?>
$(function() {
if(navigator && navigator.geolocation) {
var fallback = setTimeout(function() { fail('10 seconds expired'); }, 10000);
navigator.geolocation.getCurrentPosition(
function (pos) {
clearTimeout(fallback);
var point = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
new google.maps.Geocoder().geocode({'latLng': point}, function (res, status) {
if(status == google.maps.GeocoderStatus.OK && typeof res[0] !== 'undefined') {
var zip = res[0].formatted_address.match(/,\s\w{2}\s(\d{5})/);
if(zip) {
var zipcodepassed = zip[1];
$("#em").html(zipcodepassed);
var reps = reps_load;
var ads_repList_URLtoFullName = ads_repList_URLtoFullName_load;
var rek = ads_repList_URLtoFullName;
var rep = reps[zipcodepassed];
if (rep == undefined || rep == null || rep == "") {
$(function() {
$("#gotorep").remove();
$("#entersite").remove();
$("#entersite2").css({'display':'inline'});
});
}
var repname = rek[rep]; //i.e. shaner will be Shane Reaume in repname variable
$("#yourrep").html(repname);
$("a[href='http://devv.referadiabetic.com']").attr('href', 'http://devv.referadiabetic.com/' + rep);
}
}
});
}
);
}
});
setTimeout("function() fail('10 seconds expired');", 10000);