【问题标题】:Google Map plugin with ionic带有离子的谷歌地图插件
【发布时间】:2015-09-01 23:52:15
【问题描述】:

我必须在我的 ionic 应用程序(适用于 android)中集成一个谷歌地图圈。我从this 链接安装插件。我遵循所有步骤,但我有一个问题。当我调用 map.addCircle() 函数时,logcat 返回错误“未捕获的类型错误:未定义不是函数”。

我该如何解决这个问题?

这是我的 controller.js:

angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }


    // Wait until the map is ready status.

  });
})

.controller('MapCtrl', function($scope, $ionicLoading, $compile) {

    var geocoder;
    geocoder = new google.maps.Geocoder();
  function initialise() {

      navigator.geolocation.getCurrentPosition(onSuccess, onError); 
    function onSuccess(position){
      var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      $scope.latlng = myLatlng;
      console.log($scope.latlng);


      var mapOptions = {
        zoom: 15, 
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP, 
      }


      var map = new google.maps.Map(document.getElementById('map'), mapOptions);
      var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
      });
      map.addCircle({
          'center': myLatlng,
          'radius': 300,
          'strokeColor' : '#AA00FF',
          'strokeWidth': 5,
          'fillColor' : '#880000'
        });
      $scope.map = map; 


    }
    function onError(error){
      alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
    }   
  }
  google.maps.event.addDomListener(window, 'load', initialise);

 })

【问题讨论】:

    标签: android cordova google-maps ionic-framework


    【解决方案1】:

    使用来自 this 链接的 Angular-Google-Maps 解决。

    安装 ng-map.js 后,您可以使用以下代码从 html 页面创建圆圈:

    <shape name="circle" stroke-color="#FF0000" stroke-opacity="0.8" stroke-weight="2" fill-color="#FF0000" fill-opacity="0.35" center="<someCoordinates>" radius="10">
        </shape>
    

    【讨论】:

      猜你喜欢
      • 2014-12-21
      • 1970-01-01
      • 2015-08-24
      • 1970-01-01
      • 2019-05-02
      • 2019-07-15
      • 2019-01-21
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多