Based on JavaScript, you can locate your mobile phone and obtain the current location (No. X, street, No. X, county, city, and city, X) _ javascript skills

Source: Internet
Author: User
This article mainly introduces how to obtain information about the current location based on mobile phone location based on JavaScript (No. X, district X, city X, district X, if you need a friend, you can refer to the following nonsense and paste the js Code directly. The Code is as follows:

Function Location () {}; Location. prototype. getLocation = function (callback) {var options = {enableHighAccuracy: true, maximumAge: 1000}; this. callback = Object. prototype. toString. call (callback) = "[object Function]"? Callback: function (address) {alert (address. province + address. city); console. log ("getocation (callbackFunction) can obtain the location information object") ;}; var self = this; if (navigator. geolocation) {// the browser supports geolocation navigator. geolocation. getCurrentPosition (function (position) {// longitude var longpolling = position. coords. longpolling; // latitude var latitude = position. coords. latitude; self. loadMapApi (longpolling, latitude) ;}, self. onError, options) ;}else {// the browser does not support geolocation }}; Location. prototype. loadMapApi = function (longpolling, latitude) {var self = this; var oHead = document. getElementsByTagName ('head '). item (0); var oScript = document. createElement ("script"); oScript. type = "text/javascript"; oScript. src =" http://api.map.baidu.com/getscript?v=2.0&ak=A396783ee700cfdb9ba1df281ce36862&services=&t=20140930184510 "; OHead. appendChild (oScript); oScript. onload = function (date) {var point = new BMap. point (longpolling, latitude); var gc = new BMap. geocoder (); gc. getLocation (point, function (rs) {var addComp = rs. addressComponents; self. callback (addComp) ;}}}; Location. prototype. onError = function (error) {switch (error. code) {case 1: alert ("location service rejected"); break; case 2: alert ("location information temporarily unavailable"); break; case 3: alert ("Get information timeout"); break; case 4: alert ("Unknown error"); break ;}; // call var local = new Location (); local. getLocation (function (res) {// here is the returned geographic location information console. log (res );})

The above content is based on JavaScript that I want to introduce to you to obtain the current Location Based on Mobile Phone Positioning (No. X, street X, county X, city X, Province X). I hope you will like it.

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.