PHP for mobile phone positioning

Source: Internet
Author: User

Mobile. PHP file

When the user accesses the page, by implementing the page form hidden Encapsulation Auto-submit to get the latitude and longitude of the mobile browser and post to the server

<HTML><MetaCharSet= "UTF8"><Head><formname= "Form1"Action= "http://test.nwee.cc/ken/baidulocated.php"Method= "POST"><inputtype= "text"name= "Lat"ID= "Lat"style= "Display:none"><inputtype= "text"name= "LNG"ID= "LNG"style= "Display:none"></form><Scripttype= "Text/javascript">    varposition_option={enablehighaccuracy:true, maximumage:infinity, timeout:100000    }; varlat; varLNG; if(navigator.geolocation) {navigator.geolocation.getCurrentPosition (getpositionsuccess, Getpositionerror,    Position_option); }Else{alert ('Geolocation is isn't supported by this browser.'); }    functiongetpositionsuccess (position) {lat=Position.coords.latitude; LNG=Position.coords.longitude; //alert (' Where you are: Latitude ' + lat + ', longitude ' + LNG);fillform ();//fill out the formdocument.form1.submit ();//Post data to the server    }    functionGetpositionerror (Error) {Switch(error.code) { Caseerror. Timeout:alert ('The request to get user location timed out.'); Break;  Caseerror. Permission_denied:alert ('User denied the request for geolocation.'); Break;  Caseerror. Position_unavailable:alert ('Location information is unavailable.'); Break; default: Alert ('An unknown error occurred.'); }    }    functionFillform () {document.getElementById ('lat'). Value=lat; document.getElementById ('LNG'). Value=LNG; }</Script></Head></HTML>

located.php file

Through the Baidu positioning API for analytic positioning

<? PHP Header ("content-type:text/html; Charset=utf8 "); $url= "http://api.map.baidu.com/geocoder/v2/?location=". $_post ["Lat"]. ",". $_post ["LNG"]. " &ak=*****************************&coordtype=bd09ll&output=json "; $json file_get_contents ($url); $arr = Json_decode ($jsontrue); Var_dump ($arr);? >

PHP for mobile phone positioning

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.