HTML5 on the implementation of positioning function

Source: Internet
Author: User

<! DOCTYPE html>

<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> positioning </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 + ' shop name: ' +arr[x].name + ' distance ' +arr[x].distance + ' address ' +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>

<body>

<input type= "button" value= "Get Location" onclick= "getuserlocation ()"/>

<div id= "Locationdata" >

Location data here

</div>


</body>


<?php

/**

* Background Processing

* Nearby Branch API for McDonald's

*/

Header (' Content-type:application/json; Charset=utf-8 ');

Require "config.php";

Require "android_get_mkq_shop_controller.php";


$latitude = $_request[' latitude '); Dimension of

$latitude = 39.90403; Dimension of

$longitude = $_request[' longitude '); Longitude

$longitude = 116.4075; Longitude

$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 mins

}

}else{

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

}

echo Json_encode ($data);

?>



HTML5 on the implementation of positioning function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.