角度谷歌地图不会渲染,也不会抛出任何错误

Angular google Map will not render and throws no errors

本文关键字:错误 任何 谷歌地图      更新时间:2023-09-26

我是角度的新手,但我认为我一切都正确。这是一个非常简单的设置。

这是应用程序

var appLocations = angular.module('locations', ['uiGmapgoogle-maps']).config(function(uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure({
        // key: 'I am not providing a key',
        v: '3.17',
        libraries: 'weather,geometry,visualization'
    });
});
appLocations.controller('LocationsController', function($scope, $http) {
    $http.get('/json/locations/')
        .then(function(res){
            $scope.locations = res.data;
        });
});
appLocations.controller('MapController', function($scope, $http) {
    $http.get('/json/locations/')
        .then(function(res){
            $scope.locations = res.data;
        });
    $scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 };
});

这是标记

<div class="main1-in" ng-app="locations">
        <div ng-controller="MapController">
            <ui-gmap-google-map></ui-gmap-google-map>
        </div>
        <div class="health-care large-12 medium-11 small-12">
            <h1>Welcome</h1>
            <?php dynamic_sidebar('Welcome')?>
        </div>
        <div class="location large-12 medium-12 small-12" ng-controller="LocationsController">
            <h2>LOCATIONS</h2>
            <div class="search">
                <input type="text" class="text-field" value="Find a location" ng-model="search" placeholder="Search...">
                <span><i class="fa fa-search"></i></span>
                <div class="clear"></div>
            </div>
            <div class="clear"></div>
            <div class="location-carousel large-12 medium-12 small-12">
                <ul>
                    <li ng-repeat="location in locations | filter:search">
                        <div class="location-in"  itemscope itemtype="http://schema.org/MedicalClinic">
                            <img src="{{location.thumbnail[0]}}" alt="img" width="273" height="157">
                            <h6><span itemprop="name">{{location.Name}}</span></h6>
                            <p itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
                                <span itemprop="streetAddress">{{location.address1}} {{location.address2}}</span><br>
                                <span itemprop="addressLocality">{{location.city}}</span>,
                                <span itemprop="addressRegion">{{location.state}}</span>
                                <span itemprop="postalCode">{{location.zip}}</span>
                            </p>
                            <small itemprop="telephone">{{location.phoneNumber}}</small>
                            <a href="{{location.permalink}}" itemprop="url">Visit location page</a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>

我在控制台中没有收到任何错误。应用程序的其余部分会呈现,但地图本身不会呈现。任何帮助将不胜感激。

根据文档,您的所有操作都是正确的,除了一件事,您需要提及地图中心和地图的缩放级别才能开始,请参阅快速入门文档

<ui-gmap-google-map center='map.center' zoom='map.zoom'></ui-gmap-google-map>

map.center并且map.zoom从您提供的 MapController 中获取,本地副本对我有用。检查代码的其他部分是否有任何问题。

而且肯定,

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

到您的 CSS 中,或动态设置访问 DOM 的高度。