离子清洁 google 地图应用

ionic cleanse google map app

我在使用 google 游戏的地图时遇到问题。在第一个实例中,整个加载正确,但第二个地图未加载。我认为这可以通过一些方法解决,但没有。我拿这个是为了清除地图。

var map = document.getElementById("mapa_ubicacion");
google.maps.event.trigger(map, 'resize');

每次有人用移动设备的相机拍照时都会加载此地图,这就是为什么您可以占用很多次的原因。

$scope.cargarUbicacion = function () {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
  .getCurrentPosition(posOptions)
  .then(function (position) {
    var latitud_actual  = position.coords.latitude
    var longitud_actual = position.coords.longitude
    var mapOptions = {
              center: new google.maps.LatLng(latitud_actual, longitud_actual),
              zoom: 15,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              scrollwheel: false
          };
          map = new google.maps.Map(document.getElementById("mapa_ubicacion"), mapOptions);
          $scope.setMarker(map, new google.maps.LatLng(latitud_actual, longitud_actual), 'Yo', '');
  }, function(err) {
    // error
  });


var watchOptions = {
  frequency : 1000,
  timeout : 3000,
  enableHighAccuracy: false // may cause errors if true
};

var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
  null,
  function(err) {
    // error
  },
  function(position) {
    var latitud_actual  = position.coords.latitude
    var longitud_actual = position.coords.longitude
    var mapOptions = {
              center: new google.maps.LatLng(latitud_actual, longitud_actual),
              zoom: 15,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              scrollwheel: false
          };
          map = new google.maps.Map(document.getElementById("mapa_ubicacion"), mapOptions);
          $scope.setMarker(map, new google.maps.LatLng(latitud_actual, longitud_actual), 'Yo', '');
});
watch.clearWatch();
}

尝试在控制器的初始函数中创建单个地图实例,并将地图对象添加到范围。然后只更新您的方法中的地图位置。这帮助我解决了类似的问题。

    $scope.init = function() {

        var mapOptions = {
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel: false
       };

       var map = new google.maps.Map(document.getElementById("mapa_ubicacion"), mapOptions);
       $scope.map = map;
    }

   $scope.init();
})

在您的方法中执行以下操作:

//set map center with your coords on $scope.map
$scope.setMarker($scope.map, new google.maps.LatLng(latitud_actual, longitud_actual), 'Yo', '');