2014-05-21 81 views
1

http://plnkr.co/edit/Zd9GwG?p=preview谷歌地图动态角度

我正在处理这个谷歌地图+ angular.js的例子。我想要根据变量.i.e动态更改位置中心。我想让它成为动态中心。请建议如何做到这一点?

我想做一些事情就像这样。

//代码放在这里

//Add the requried module 'angular-ui' as a dependency 
angular.module('maptesting', ['ui.directives']); 

function MapCtrl($scope) { 

    $scope.lat = 35.120922 ; 
    $scope.long = -89.97731 ; 
    var ll = new google.maps.LatLng($scope.lat, $scope.long); 
    $scope.mapOptions = { 
     center: ll, 
     zoom: 15, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    //Markers should be added after map is loaded 
    $scope.onMapIdle = function() { 
     //alert("DF"); 
     if ($scope.myMarkers === undefined){  
      var marker = new google.maps.Marker({ 
       map: $scope.myMap, 
       position: ll 
      }); 
      $scope.myMarkers = [marker, ]; 
     } 
    }; 
     $scope.showMarkerInfo = function(marker) { 
     $scope.myInfoWindow.open($scope.myMap, marker); 
    }; 

    $scope.changeval = function(){ 
     $scope.lat = 13.0810 ; 
     $scope.long = 80.2740 ; 


    }; 





} 
+0

应该是什么动态?地图的中心?标记?更多细节请。 – Alp

+0

为什么关闭?我编辑了这个问题。我需要回答先生 –

回答

8

你需要以刷新地图观看在范围的变化。

Demo Plunkr

(只使用地图上方的输入字段来实时更改地图的中心)

的重要组成部分,是$scope.$watch

var updateCenter = function() { 
    var ll = new google.maps.LatLng($scope.lat, $scope.long); 
    $scope.myMap.panTo(ll); 
    // eventually more stuff 
    } 
    $scope.$watch('lat', updateCenter); 
    $scope.$watch('long', updateCenter); 
+0

尼斯。有没有什么方法可以显示两个位置之间的方向? –

+0

它在浏览器中正常工作,但在phoneGap中 - Ios标记不显示 –

+0

您需要查看Google地图的API文档以了解这些基本问题。 – Alp