How to implement the city positioning of the mobile and urban area code Adcode

How to achieve the city positioning of the mobile and urban area code adcode? This issue may be often seen in our daily study or work. I hope that you can give you a deep harvest through this issue. Below is the reference content brought by Xiaobian, let’s take a look!

  1. AMAP.CITYSEARCH () [)

First in the Gaode open platform registration to apply for position permission. Website; Gaode open platform

Script

              

High use Demand API

Requirements: Apple equipment uses IP positioning, other use GPS positioning
   function getLocation () {var u = navigator.USERAGENT; var ua = navigator. UseERAgent.tolowercase (); var isandroid = u.indexof ('android')> -1 || u.indexof ('ADR')> -1; // android terminal var isios = !! u.match (/ \ i [^;] +; (u;)? CPU. + Mac OS X /); // iOS terminal// GPS positioning Function locationforgps () {/ ********* Track tag ********** / console.log ('GPS positioning start +++); Var Map, Geolocation ; // Load the map, call the browser positioning service map = new amap.map ('iCenter'); map.plugin ('Amap.geLocation ", function () {geolocation = new amap.geology ({Enablehighaccuracy: false, / / Whether to use high-precision positioning, default: True Timeout: 1000, // More than 10 seconds stop positioning, default: infinity}); map.addControl (geolocation); geolocation.getCurrentPosition (); // getCityInfo is Gao De GPS positioning One way inside, first return IP positioning data, because IP positioning may be inaccurate, so use GPS data to correct // geolocation.getCityInfo (Function (status, result) {/ ******** Track mark ********** / console.log ('starts with GPS synchronization IP positioning, data writing ++ + '); if (status ===' complete '&& results') {/ ************ / console. LOG ('synchronous IP positioning is successful, data writing +++); if (isnull (sessionStorage.GetItem (' autofoot '))) {/ ******** Track mark ***** ***** / console.log ('unspecified check has last positioning data, data writing +++ "); let cityadcode = result.adcode; let cityname = result.city; sessionStorage.SetItem (' autobrooselocationct) ', cityname; sessionStorage.SetItem (' autofhooselocationCode ', cityadcode; / ********* Track mark ********** / console.log (' synchronous IP positioning ends, data writing is completed +++); }}}); AMAP.Event.Addlistener (Geology, 'Complete', OnComplete); // Return the positioning information amap.event.addlistener (geolocation, 'error', oneerror); // Return the positioning error information}); / / GPS positioning success function oncomplete (data) {console.log (data) / ******** Track tag ********** / console.log ('GPS positioning start +++ '); // GSP positioning accurate to the area, returned ADCODE to the area of ​​the city, // want to get the city's Abcode needs to use Dilde's Another API, urban area query let cityname = data.addresscompOnenet.city; let geocoder = new amap.geocoder ({}); // geocoding, returning geocoding result, geocoder.getlocation (cityname, function (result) {ix (status === 'Complete' && Result .info === 'ok') {/ ********* Track mark ********** / console.log ('GPS positioning is successful, processing positioning data +++) ; / ********* Track mark ********** / console.log ('performing data writing, overridden data ++++++ of synchronous IP); let cityadcode = result. GeoCodes [0] .adcode; sessionStorage.SetItem ('AutomChooselocationct'; sessionStorage.SetItem ('automchool); / ********* Track tag ********** / console.log ('GPS positioning ends, data writing is completed +++);}});} // GPS positioning failed Function OneError () {/ ***** **** Track mark ********** / console.log ('GPS positioning failed to enable IP positioning +++); LocationForip (true); / ********* Track mark ********* / console.log ('GPS-IP ++ ...')}} // ip Location Function LocationForip (TAP) {/ ********* Track tag ********* / if (tap) {console.log ('GPS positioning failed to enable IP positioning +++);} / ******** Track mark *** ******* / console.log ('IP positioning +++); var citysearch = new amap.citysearch (); // automatically obtain user IP, return to the current city citySearch.getlocalCity (Function) (STATUS, Result) {IF (status === 'complete' && result.info === 'ok') {if (result && result.city& result.bounds) {let getuserLocation = result.city, getUserLocationcode = Result.adcode; / ** ******* Track mark ********** / console.log ('IP positioning successfully, start checking if there is a last positioning data +++); if (isnull (sessionStorage.getItem ('AutomChooselocationct')))) {/ ******** Track mark ********** / console.log ('IP positioning is successful, no detection check has last positioning data, Data writing +++ '); sessionStorage.SetItem (' automchool); sessionStorage.SetItem ('Automooselocationcode', GetUserLocationcode);/ ********* Track mark ********** / console.log ('IP positioning is successful, data write end +++);}}} else {/ * ******** Track mark ********** / console.log ('IP positioning failed, data write end +++);}})}}} { / ********* Track mark ********** / console.log ('iOS device enables IP positioning'); LocationForip (false);} else {/ ***** **** Track mark ********** / console.log ('Non-iOS device enables GPS positioning'); locationforgps ()}}}; 

Thank you for reading! After reading the above, do you know how to achieve the city positioning of the mobile side and the urban area code adcode understand? I hope that the content of the article will help everyone. If you want to know more about the content, please pay attention to Tumi Yun Industry Information Channel.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment