About automatic positioning

Usually two scenarios, PC and mobile sides positioned.

The mobile terminal more convenient, because GPS, Compass, high precision positioning can be achieved, it is not as well as base station location, or network location.

When done with the Android APP before a Baidu's positioning API, an application Key applications like, also has the option of positioning by which way, more convenient.

If it is a small program that can be used Tencent API, obtain latitude and longitude, then into the address, it is not complicated.

On the PC side, accidentally into a pit, it is through the IP localization is more complex, and ultimately choose Baidu SDK way around.

Supplement, H5 also has a function navigator.geolocation.getCurrentPosition (), but not used.

You can refer to: https://blog.csdn.net/liuxiaochang_2011/article/details/86537328

IP solutions considered using the mapping package and open source ip address, ip Taobao also used other means, the former requires regular data updates, which limited the number of visits, with more than a few times gg, then give up.

IP is the most important positioning is not accurate, some with agents, and some can only locate the position of the root servers.

Baidu posted below SDK solutions.

Now add in index.html

<script src="http://api.map.baidu.com/api?v=3.0&ak=XXXX"></script>

Then add in the methods in vue

getLocation () { 
      this.loading = to true; 
      var = new new BMap.Geolocation Geolocation (); 
      // open SDK assisted positioning 
      geolocation.enableSDKLocation (); 
      geolocation.getCurrentPosition (function (R & lt) { 
        IF (this.getStatus () == BMAP_STATUS_SUCCESS) { 
// new new BMap.Marker var MK = (r.point); 
          Alert ( 'location:' + r.point.lng + ',' + r.point.lat); 
          this.loading = to false; 
          this.form.location = 'location:' + r.point.lng + ',' + r.point.lat; 
// $ ( "# MyLocation") text ( "automatic positioning");. 
        } the else { 
          alert ( 'failed state' + this.getStatus ()); 
          this.loading = to false;
        }
      });
    },

  

Guess you like

Origin www.cnblogs.com/marszhw/p/12635586.html