html5關於定位功能的實現

來源:互聯網
上載者:User

標籤:android   style   http   io   os   ar   java   for   sp   

<!DOCTYPE html>

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <!--meta name="format-detection" content="telephone=no"/>

    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"-->

    <title>定位</title>

    <script type="text/javascript" src="./js/jquery-2.0.3.min.js"></script>

<!--    <link href="./css/style.css" rel="stylesheet" type="text/css"/>-->

    <script>

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 + "<br />")

                }

                //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;

}

}

</script>

</head>

<body>

<input type="button" value="get location" onclick="getUserLocation()"/>

<div id="locationData">

Location data here

</div>


</body>

</html>


<?php

/**

 * 幕後處理

 * 附近分店 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);

?>



html5關於定位功能的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.