Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度谷歌地图_Angularjs_Google Maps - Fatal编程技术网

Angularjs 角度谷歌地图

Angularjs 角度谷歌地图,angularjs,google-maps,Angularjs,Google Maps,我不知道如何从google maps实例调用fitBounds()。我试图在uiGmapGoogleMapApi解析后调用它,但我不知道在哪里/如何访问此方法。从vanilla js实现中,您可以调用map.fitBounds(bounds),但我不确定angular GoogleMaps v2.2.1中的等价物是什么,谢谢您的帮助 编辑 我通过将控件属性添加到scope.map,然后在uiGmapIsReady解析时调用getGMap()来实现这一点 uiGmapGoogleMap

我不知道如何从google maps实例调用fitBounds()。我试图在uiGmapGoogleMapApi解析后调用它,但我不知道在哪里/如何访问此方法。从vanilla js实现中,您可以调用map.fitBounds(bounds),但我不确定angular GoogleMaps v2.2.1中的等价物是什么,谢谢您的帮助

编辑

我通过将控件属性添加到scope.map,然后在uiGmapIsReady解析时调用getGMap()来实现这一点

      uiGmapGoogleMapApi.then(function(maps) {
        scope.bounds = new maps.LatLngBounds();
        scope.map = {
          center: {
            latitude: 47.60427,
            longitude: -122.33825
          },
          zoom: 16,
          polys: [],
          bounds: {},
          control: {} // add this property

        };
        traceVehicle(scope.tripDetails);
      });
      // add uiGmapIsReady and call getGMap()
      uiGmapIsReady.promise(1).then(function(instances) {
        instances.forEach(function(inst) {
          var map = inst.map;
          var uuid = map.uiGmap_id;
          var mapInstanceNumber = inst.instance; // Starts at 1.
          var gMap = scope.map.control.getGMap(); // assign getGMap();
          gMap.fitBounds(scope.bounds);
        });
      });



  function traceVehicle(selectedTrip) {
    var rawPolys = [];
    var polylineObj = {
      id: 1,
      path: [],
      stroke: {
        color: '#6060FB',
        weight: 3
      },
      editable: false,
      draggable: false,
      geodesic: true,
      visible: true
    };
    scope.polylines = [];
    if(selectedTrip.locations.length > 0) {
      angular.forEach(selectedTrip.locations, function(v, i) {
        polylineObj.path.push({ latitude: v.lat, longitude: v.lon });
        scope.bounds.extend({ lat: v.lat, lng: v.lon });
      });
      rawPolys.push(polylineObj);
      scope.map = {
        center: {
          latitude: polylineObj.path[(Math.round(polylineObj.path.length/2) -1)].latitude,
          longitude: polylineObj.path[(Math.round(polylineObj.path.length/2) -1)].longitude
        },
        zoom: 16,
        polys: rawPolys
      };
      scope.map.fitBounds(scope.bounds); // how to call fitBounds()?

您需要
$scope.map
作为google地图对象。目前,这只是一些选择

var mapOptions = {
    zoom: 16,
    polys: [],
    bounds: {},
    center: new google.maps.LatLng(47.60427, -122.33825),
    mapTypeId: google.maps.MapTypeId.TERRAIN
};

$scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);
$scope.map.fitBounds(YOUR_CODE_FOR_BOUNDS);

scope.map
只是一个对象。您想为
scope.Map
创建一个
google.maps.Map
对象。至少从你分享的片段中。。。