2017-07-28 8 views
1

私の質問は、既存のマーカーの緯度と経度をどのように取るかです。私に説明してみましょう:私は、ブラウザ上のページに入力したとき、私はアドレスを使用して、マーカーの位置を表示します。文字列の位置から取られたデフォルトマーカーの緯度と経度を返す

<ng-map ng-if="null != evaluation" default-style="false" zoom="16" center="{{ '{{ getAddress() }}' }}" style="width: 100%; height: 430px;"> 
       <marker centered="true" position="{{ '{{ getMarkerPosition() }}' }}" draggable="true" on-dragend="onMarkerDragEnd($event)"></marker> 
    </ng-map> 

角部:

$scope.getMarkerPosition = function() { 
      if (!$scope.address.mapPinLocationLatitude || !$scope.address.mapPinLocationLongitude) { 
       return $scope.getAddress(); 
      } 
      return [$scope.address.mapPinLocationLatitude, $scope.address.mapPinLocationLongitude] 
     }; 


    $scope.getAddress = function() { 
      //building the adress by getting the objects that are used for creating an address object 

      return streetString + ', ' + address; //streetString will be a string that has the complete address 
     }; 

    $scope.onMarkerDragEnd = function ($event) { 
      $scope.address.mapPinLocationLatitude = $event.latLng.lat(); 
      $scope.address.mapPinLocationLongitude = $event.latLng.lng(); 

     uptadeRegions(); 
     }; 

私はマーカーを移動する場合はLATとログが存在して、 2つの配列を返すgetMarkerPositionメソッドしかし、地図上でマーカーを動かさなければ、緯度と経度をどのように取得するのですか?デフォルトは0で、解決方法はわかりません。ありがとう、

EDIT:

app.controller('MapController', 
['$scope', 'NgMap','$state', 'SelectOptionsService', '$rootScope', '$q','GeoCoder', 
    function ($scope, NgMap, $state, SelectOptionsService, $rootScope, $q, GeoCoder) { 

答えて

1

ですから、マーカー位置のアドレスを使用して、あなたはそれが初期化されています中に& LNG LATを取得したいですか?あなたは(ngMapが提供する)GeoCoderサービス

何かのように使用することができます

<marker ... geo-callback="geoCallback()"></marker> 

が読んマーカーにあなたはgeo-callback属性を使用することができ、

app.controller('MapController', 
['$scope', 'NgMap','$state', 'SelectOptionsService', '$rootScope', '$q','GeoCoder', 
    function ($scope, NgMap, $state, SelectOptionsService, $rootScope, $q, GeoCoder) { 
     //hired by marker:geo-callback 
     $scope.geoCallback = function() { 
      GeoCoder.geocode({ 
       address: $scope.getAddress() 
      }).then(function(result) { 
       //explore this, you may got the position in: result[0].geometry.location 
       console.log('A place object is: ', result); 
      }); 
     }; 
     ... 
     //your getAddress function 
     $scope.getAddress = function() { 
     }; 
}]); 

とhtmlで約geo-callback here

+0

私は正確に 'app.controller( 'TestCtrl1'、['$ scope'、 'GeoCoder'、function($ scop)のようなコントローラ – IleNea

+0

のように注入する方法を正確には知らないe、GeoCoder){}] '、どうやってコントローラを定義しますか? – Fetrarij

+0

関数getAddress()は関数ではないと今言われています。 – IleNea

関連する問題