【问题标题】:ionic cleanse google map app离子清洁谷歌地图应用程序
【发布时间】:2015-06-27 19:13:36
【问题描述】:

我在使用 google play 地图时遇到问题。在第一个实例中,整个加载正确,但第二个地图没有加载。我认为这将解决一些方法,但没有。我已经用这个来清理地图了。

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();
}

【问题讨论】:

    标签: google-maps cordova ionic


    【解决方案1】:

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

        $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', '');
    

    【讨论】:

    • 这对我不起作用,和其他一样,第一次加载但第二次不再改变。
    • 我很高兴能帮上忙,没问题 :)
    • 我离开我的新话题,这里还有一个问题jejeje,希望不要打扰:) stackoverflow.com/questions/29775699/…
    猜你喜欢
    • 2018-09-12
    • 1970-01-01
    • 2023-03-21
    • 2018-07-21
    • 2019-07-15
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多