HTML5定位延时,html5关于定位功能的实现

定位

function getUserLocation(){

//check if the geolocation object is supported,if so get position

if(navigator.geolocation)

navigator.geolocation.getCurrentPosition(displayLocation,displayError);

else

document.getElementById("locationData").innerHTML="Sorry-your browser doesn't support geolocation !";

}

function displayLocation(position){

$.post('process.php','latitude=' + position.coords.latitude + '&longitude=' + position.coords.longitude,function(d){

console.log(d);

var arr = JSON.parse(d);

//alert(arr[0].name);

var x;

for (x in arr)

{

document.write('id:'+ arr[x].id + ' 店名:'+arr[x].name + ' 距离'+arr[x].distance + ' 地址'+arr[x].address + "
")

}

//document.getElementById("locationData").innerHTML=arr;

});

}

function displayError(error) {

//get a reference to the HTML element forwriting result

var locationElement =$("locationData");

//find out which error we have, output message accordingly

switch(error.code) {

case error.PERMISSION_DENIED:

locationElement.innerHTML= "Permission was denied";

break;

case error.POSITION_UNAVAILABLE:

locationElement.innerHTML= "Location data not available";

break;

case error.TIMEOUT:

locationElement.innerHTML= "Location request timeout";

break;

case error.UNKNOWN_ERROR:

locationElement.innerHTML= "An unspecified error occurred";

break;

default:

locationElement.innerHTML= "Who knows what happened…";

break;

}

}

Location data here

/**

* 后台处理

* 附近分店 API  For 麦当劳

*/

header('Content-Type: application/json; charset=utf-8');

require "config.php";

require "android_get_mkq_shop_controller.php";

$latitude   = $_REQUEST['latitude'];    //维度

//$latitude   = 39.90403;    //维度

$longitude  = $_REQUEST['longitude'];   //经度

//$longitude  = 116.4075;   //经度

$data = get_mkq_shop($latitude,$longitude);

$memcache = new Memcache;

if ($memcache->connect('localhost', 11211) && USE_MEMCACHE) {

$memcache_key = 'android_mkq_get_mkq_shop'.$latitude.'_'.$longitude;

if (!$data = $memcache->get($memcache_key)) {

$data = get_mkq_shop($latitude,$longitude);

$memcache->set($memcache_key,$data,false,900); // cache time 15 mins

}

}else{

$data = get_mkq_shop($latitude,$longitude);

}

echo json_encode($data);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值