2016-10-19 10 views
-2

私はイオンに慣れていません。 私は、マーカーdragendイベントでテキストの値を変更する必要があることを指摘したいと思います。 $ apply()を使用していますが、動作していません。ここ は私のコントローラスクリプトです:

.controller('RequestForRideCtrl', function ($scope, $ionicHistory, $http, $ionicPopup, $state, $window, $compile,$timeout) { 

var Slat, Slng, Dlat, Dlng; 
var Slatlng, Destination; 
$scope.location = {}; 
$scope.location1 = {}; 

$scope.init = function() { 
    var Smarker, Dmarker; 
    var flag; 

    var myLatlng = new google.maps.LatLng(19.9975, 73.7898); 
    var mapOptions = { 
    center: myLatlng, 
    zoom: 16, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map"), 
    mapOptions); 

    var contentString = "<div><a ng-click=''>Click</a></div>"; 
    var compiled = $compile(contentString)($scope); 
    var infowindow = new google.maps.InfoWindow({ 
    content: compiled[0] 
    }); 


navigator.geolocation.getCurrentPosition(function (pos) { 
    $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)); 

    Slat = pos.coords.latitude; 
    Slng = pos.coords.longitude; 
    var myLatlng = new google.maps.LatLng(Slat, Slng); 
    $scope.map.setCenter(myLatlng); 

    Smarker = new google.maps.Marker({ 
     position: myLatlng, 
     map: $scope.map, 
     draggable: true, 
     title: 'Source', 
     label: 'S' 
    }); 
    google.maps.event.addListener(Smarker, 'drag', function (event) { 

     var lat = document.getElementById("latbox").value = this.getPosition().lat(); 
     var lng = document.getElementById("lngbox").value = this.getPosition().lng(); 
Slatlng = new google.maps.LatLng(lat, lng); 
     flag=1; 
     getPosition(Slatlng, flag); 
    })}); 


$scope.$on('destination', function (evt, value) { 
    $scope.variable = value; 

    var Dlat = $scope.variable.geometry.location.lat(); 
    var Dlng = $scope.variable.geometry.location.lng(); 
    var myLatlngD = new google.maps.LatLng(Dlat, Dlng); 
    $scope.map.setCenter(myLatlngD); 

    var Dmarker = new google.maps.Marker({ 
     position: myLatlngD, 
     map: $scope.map, 
     draggable: true, 
     title: 'Destination', 
     label: 'D' 
    }); 

    google.maps.event.addListener(Dmarker, 'drag', function (event) { 

     var lat = document.getElementById("latbox1").value = this.getPosition().lat(); 
     var lng = document.getElementById("lngbox1").value = this.getPosition().lng(); 
     Destination = new google.maps.LatLng(lat, lng); 
     flag = 0; 
     getPosition(Destination, flag); 
    }); 


function getPosition(marker, flag) { 
    if (flag == 1) { 
     var geocoder = new google.maps.Geocoder(); 
     geocoder.geocode({'latLng': marker}, function (results, status) { 
     if (status === google.maps.GeocoderStatus.OK) { 
      if (results[1]) { 
      $scope.location.formatted_address = results[1].formatted_address; 
      $timeout(function() { 
       $scope.$apply(function() { 
       console.log('in source'); 
       }); 
      }, 2000); 
      } else { 
      console.log('Location not found'); 
      } 
     } else { 
      console.log('Geocoder failed due to: ' + status); 
     } 
     }); 
    } 
    else { 
     var geocoder = new google.maps.Geocoder(); 
     geocoder.geocode({'latLng': marker}, function (results, status, element) { 
     if (status === google.maps.GeocoderStatus.OK) { 
      if (results[1]) { 
      $scope.location1.formatted_address = results[1].formatted_address; 
      $timeout(function() { 
       $scope.$apply(function() { 
       console.log('in des'); 
       }); 
      }, 2000); 
      } else { 
      console.log('Location not found'); 
      } 
     } else { 
      console.log('Geocoder failed due to: ' + status); 
     } 
     }); 
    } 
    } 

が、これは私のhtmlです:

<ion-pane> 
      <div id="map" data-tap-disabled="true"> 
      </div> 
      <div id="floating-panel" style=""> 
       <input type="text" id="source1" placeholder="Source" location-suggestion location="location" ng-model="location.formatted_address"> 
      </div> 
      <div id="floating-panel1" style=""> 
       <input type="text" id="address" placeholder="Destination" location-Destination location1="location1" ng-model="location1.formatted_address"> 
      </div> 
</ion-pane> 

は、この問題を整理するために私を助けて。

+0

どのようなエラーが表示されますか?それは「ダイジェストはすでに進行中ですか? – Tom

+0

実際にはエラーが発生しません。マーカ変更時にテキストボックス値を更新するだけですが、コピー先のbtがソースマーカでうまく動作しません。 –

答えて

1

setTimeoutの代わりに$timeoutを試してみてください。 setTimeout関数は、$digestサイクルをトリガーしません。

+0

は動作しません。 –

関連する問題