AngularJS 谷歌地图指令

新手上路,请多包涵

我正在尝试使用 angularjs 和我找到的用于实例化 GMaps 的指令开发一个应用程序: http ://nlaplante.github.io/angular-google-maps/#!/usage。我按照所有步骤操作,但无法渲染地图!它没有返回任何错误!

在 HTML 中

<html ng-app="Maptesting">

 <div ng-view></div>

 <script src="app/map.js">
</script>

在控制器中:

 angular.module('Maptesting', ['google-maps'])

.controller('CtrlGMap', ['$scope', function($scope) {
        $scope.center = {
            latitude: 45,
            longitude: -73
        };

        $scope.markers = [];
        $scope.zoom = 8;

}])

原文由 Facu Ferrari 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 497
2 个回答

不同的答案,但我觉得 google-maps-directive 对我来说更难使用。因此,我为自己的项目创建了一个名为 ng-map 的 google maps angularjs 指令。这不需要任何 Javascript 编码来实现简单的功能。

看起来像这样

<map zoom="11" center="[40.74, -74.18]">
  <marker position="[40.74, -74.18]" />
  <shape name="circle" radius="400" center="[40.74,-74.18]" radius="4000" />
  <control name="overviewMap" opened="true" />
</map>

原文由 allenhwkim 发布,翻译遵循 CC BY-SA 3.0 许可协议

我有这个问题。解决方案是确保在您的 CSS 中包含“angular-google-map-container”类的高度值。您不必将此类添加到您的 HTML;它已经包含在 angular-google-maps 指令的 Javascript 中。 将高度添加为内联样式将不起作用,因为此特定类是通过指令中的嵌入添加的。

 .angular-google-maps-container {
    height: 400px;
}

原文由 zewt112 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题