2016-08-09 20 views
3

我正在嘗試從Google地圖中點擊或保存離子事件時獲取座標。如何獲取座標值,同時在離子谷歌地圖中長時間輕按/按住

雖然抱着我在瀏覽器控制檯中獲取值沒有進入設備。

如何清除此問題?我需要在使用離子框架[谷歌地圖]的移動應用程序中持有/錄像時獲取值。

任何幫助將不勝感激。提前感謝。

.controller('HomeCtrl', function ($scope, $rootScope, $cordovaGeolocation, $ionicLoading, $ionicGesture) { 

     $ionicLoading.show({ 
      template: '<ion-spinner icon="bubbles"></ion-spinner><br/>Acquiring location!' 
     }); 

     var posOptions = { 
      enableHighAccuracy: true, 
      timeout: 20000, 
      maximumAge: 0 
     }; 
     $cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) { 
      var lat = position.coords.latitude; 
      var long = position.coords.longitude; 
      $rootScope.currentlat = lat; 
      $rootScope.currentlong = long; 
      var myLatlng = new google.maps.LatLng(lat, long); 
      $rootScope.myLatlng = myLatlng; 
      var mapOptions = { 
       center: myLatlng, 
       zoom: 10, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 

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

      $scope.map = map; 
      marker = new google.maps.Marker({ 
       position: myLatlng, 
       map: $scope.map 
      }); 

      var element = angular.element(document.querySelector('#map')); 
      $ionicGesture.on('hold', function(e){ 
       $scope.$apply(function() { 
        alert('hold happens'); 
        google.maps.event.clearListeners(map, 'click'); 
        google.maps.event.addListener(map, 'click', function(event) { 
         alert(event.latLng); 
        }); 
       }); 
      }, element); 

      google.maps.event.addListener(marker, "click", function (event) { 
      }); 

      $ionicLoading.hide(); 
     }, function (err) { 
      $ionicLoading.hide(); 
      console.log(err); 
     }); 

    } 

回答

2

我覺得你的問題是,您使用

$ionicGesture.on('hold')

標誌性的使用科爾多瓦和科爾多瓦谷歌地圖都有自己的事件處理程序的「地圖」是相關的本地視圖不會的JavaScript。你可以詳細閱讀here

因此,一旦設備已準備就緒

var map  = new google.maps.Map(document.getElementById("map"), mapOptions), 
     longClick = plugin.google.maps.event.MAP_LONG_CLICK; 

    map.on(longClick, function (latLng) { 

    var selectedLatLocation = latLng.lat.toString(); 
    var selectedLongLocation = latLng.lng.toString(); 

    alert(selectedLatLocation, selectedLongLocation); 


    });