zoukankan      html  css  js  c++  java
  • 百度地图(34)-GL 定位

    1. 三维定位同二维定位类似,也包括浏览器定位、IP定位、SDK辅助定位。

    2. 浏览器定位

     1   /**
     2    * 浏览器定位
     3    */
     4   function geoLocation() {
     5     var geoLocation = new BMapGL.Geolocation();
     6     geoLocation.getCurrentPosition(function (r) {
     7       if(this.getStatus() == BMAP_STATUS_SUCCESS){
     8         var mk = new BMapGL.Marker(r.point);
     9         map.addOverlay(mk);
    10         map.panTo(r.point);
    11         alert('您的位置:' + r.point.lng + "," + r.point.lat);
    12       }
    13       else {
    14         alert('failed' + this.getStatus());
    15       }
    16     });
    17   }

    3. IP定位

     1  /**
     2    * IP定位
     3    */
     4   function cityLocation() {
     5     function myFun(result) {
     6       var cityName = result.name;
     7       map.setCenter(cityName);
     8       alert("当前城市"+cityName);
     9     }
    10     var myCity = new BMapGL.LocalCity();
    11     myCity.get(myFun);
    12   }

    4. 辅助定位

     1  /**
     2    * SDK辅助定位
     3    */
     4   function sdkLocation() {
     5     var geoLocation = new BMapGL.Geolocation();
     6     geoLocation.enableSDKLocation();
     7     geoLocation.getCurrentPosition(function (r) {
     8       if(this.getStatus() == BMAP_STATUS_SUCCESS){
     9         var mk = new BMapGL.Marker(r.point);
    10         map.addOverlay(mk);
    11         //map.panTo(r.point);
    12         console.log('您的新位置:' + r.point.lng + "," + r.point.lat);
    13       }
    14       else {
    15         alert('failed' + this.getStatus());
    16       }
    17     });
    18   }

    5. 页面显示

    6. 源码地址

    https://github.com/WhatGIS/bdMap

  • 相关阅读:
    About Face 摘录
    断言的使用
    C#中值传递和引用传递
    C++技巧之断言Assert
    About Face 一 目标导向设计
    About Face 二 设计行为与形态
    C++中引用传递与指针传递区别
    一个新的时代SoLoMo
    离散数学笔记算法部分
    汪教授的离散数学20110308 谓词与量词2
  • 原文地址:https://www.cnblogs.com/googlegis/p/14707383.html
Copyright © 2011-2022 走看看