• Ionic 调用百度插件和使用百度地图


    ionic 中ngcordova提供基于谷歌地图定位功能

    下面开启项目之旅
    1、新建项目
    ionic start Ionic_barcode blank
    cd Ionic_barcode
    ionic platform add Android
    2、 添加百度地图定位插件

    cordova plugin add https://github.com/liyujun1989/cordova-qdc-baidu-location

    百度地图定位插件地址: https://github.com/liyujun1989/cordova-qdc-baidu-location
    里面有插件的使用方法

    3、使用百度地图插件
    在index.html中
    在controller中调用地图的方法

    $scope.tirarFoto = function(){
          /*alert("开始定位");*/
          var map = new BMap.Map("allmap");
          map.centerAndZoom(new BMap.Point(116.331398,39.897445),11);
          map.enableScrollWheelZoom(true);
        baidu_location.getCurrentPosition(function(data){
           $scope.data=data;
           $rootScope.team=data;
        }, function(err){
          alert("错误:"+err)
        });
    };

    4、 地图展示页面

    <ion-view view-title="百度插件定位">
      <ion-content class="padding">
        <button class="button button-block button-positive icon-left "  ng-click="tirarFoto()">
          获取地理定位
        </button>
       </br></br>
       <p>定位数据</p></br></br>
       {{data}}
       <p>数据2</p>
       {{team}}</br></br>
        <div id="allmap"></div>
      <div id="r-result">
        经度: <input id="longitude" type="text" style="100px; margin-right:10px;" />
        纬度: <input id="latitude" type="text" style="100px; margin-right:10px;" />
        <input type="button" value="查询" onclick="theLocation()" />
      </div>
      </ion-content>
    </ion-view>

    整个百度地图的调用就完成了

    1.当接口无法访问
    百度地图、自定义API无法访问,远程调试结果显示404
    原因是cordova 5.x的版本增加了“Content-Security-Policy”用于解决安全访问的问题。默认情况下,只能访问本机资源。
    解决方法:
    1.添加白名单插件,在项目目录下执行
    ionic plugin add cordova-plugin-whitelist
    2.在index.html头部增加

    <meta http-equiv="Content-Security-Policy" content="script-src * 'unsafe-eval'; connect-src * 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src *" >

    2.百度地图无法显示

    <script src="http://api.map.baidu.com/api?v=2.0&ak=HumGuK48Lis3kPdlHZBxvbvsqgHySljX"></script>
  • 相关阅读:
    前端数组对象名字排序有效方法
    IntelliJ IDEA项目更新静态文件时每次需要重新运行不方便,那么需要配置文件使得不用每次修改文件需要重新运行
    新建项目用flyway数据迁移时报错找不到flyway org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource
    docker用户映射
    ceph概念介绍
    ansible开发篇
    rancher安装k8s
    mysql 根据条件导出文件到系统
    Python c = a >b? a:b 语法
    html转pdf或者图片wkhtmltopdf wkhtmltoimage
  • 原文地址:https://www.cnblogs.com/liyujun1988/p/5581994.html
Copyright © 2020-2023  润新知