使用W3C Geolocation返回的Position
Using Position returned from W3C Geolocation
FindMyLocation的定义如下:
function FindMyLocation(callback) {
if (navigator.geolocation) {
var locationMarker = null;
if (locationMarker) {
return;
}
navigator.geolocation.getCurrentPosition(
function(position){
pos = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
addMarker(
position.coords.latitude,
position.coords.longitude,
"You are here"
);
setTimeout(function(window) {
callback.call(pos);
}, 1000);
},
function (geoPositionError) {
switch (geoPositionError.code) {
case 0:
alert('An unknown error occurred, sorry');
break;
case 1:
alert('Permission to use Geolocation was denied');
break;
case 2:
alert('Couldn''t find you...');
break;
case 3:
alert('The Geolocation request took too long and timed out');
break;
default:
}
},
timeoutCallback, 10, {maximumAge:60000, timeout:50000, enableHighAccuracy:true}
);
var positionTimer = navigator.geolocation.watchPosition(
function( position ){
updateMarker(
locationMarker,
position.coords.latitude,
position.coords.longitude,
"Updated / Accurate Position"
);
}
);
setTimeout(
function(){
// Clear the position watcher.
navigator.geolocation.clearWatch( positionTimer );
},
(1000 * 60 * 5)
);
} else {
alert("Your phone browser doesn't support geolocation.");
}
}
function timeoutCallback(){
alert('Hi there! we are trying to locate you but you have not answered the security question yet.'n'nPlease choose "Share My Location" to enable us to find you.');
}
我的主页上运行着以下代码:
FindMyLocation(function() {
myPos = this;
});
当我在回调中console.log myPos时,我看到了值。然而,我希望能够在这个回调之外使用myPos来进行距离计算。现在,它不起作用。
请帮忙。
<script lang="JavaScript" type="text/javascript">
$.post(window.baseUrl + 'includes/tagmap.php',
{ name:"<?php echo $value->business_name; ?>",
x: "<?php echo $value->x; ?>",
y: "<?php echo $value->y; ?>",
action:"populate"}, function(data){
var locdata = $.parseJSON(data);
function ShowMyLocation() {
FindMyLocation(function(myPos) {
myPos = this; addMarker(locdata.x,locdata.y,locdata.name);
})
FindMyLocation();
}
ShowMyLocation();
});
</script>
相关文章:
- 节点导出返回一个空对象
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 控制台返回var不是't定义,但它是
- 从函数返回角度承诺
- Javascript返回值只在循环中返回一次
- 从控制器返回后Ajax启动事件激发
- CKFinder 3为所选文件返回错误的URL
- 如何在d3.js中返回路径的y坐标
- 如何从jquery函数返回变量
- 使用W3C Geolocation返回的Position
- jQuery position().top返回0,而不是实际值
- Safari (Mac OS X Lion) 将错误的纪元时间值返回给 position.timestamp 调用
- jQuery的css(),offset()和position()函数不返回CSS属性的小数部分
- Jquery offset().left和position().lift返回意外值
- 返回position.left,带有Bootstrap偏移
- position()返回始终相同的位置
- 设置时避免返回页面顶部position to fixed with jQuery
- jQuery position方法,如果CSS位置稍后被设置为静态以外的任何内容,则返回不同的值
- JQuery position()返回safari中的相对位置