简体   繁体   English

Google Map Angular JS

[英]Google Map Angular JS

I have the following code: 我有以下代码:

<script>
//google maps integration
function initializeMap() {
    var mapCanvas = document.getElementById('map-canvas');
    var mapOptions = {
        center: new google.maps.LatLng(angular.element(document.getElementById('map-canvas')).scope().latitude, angular.element(document.getElementById('map-canvas')).scope().longitude), 
        zoom: 10,
        mapTypeId: google.maps.MapTypeId.HYBRID
    }
    var map = new google.maps.Map(mapCanvas, mapOptions);
}
google.maps.event.addDomListener(window, 'load', initializeMap);

<div id="map-canvas" style="width: 95%; height: 40%; background-color: #CCC; margin-left: auto; margin-right: auto;"></div>

The script for using 'google' is imported (and works, otherwise I would get an error in the console), however I see a gray box every time - even if I change the values in google.maps.LatLng to real numbers instead of the angular values from above. 使用“ google”的脚本已导入(并且可以正常工作,否则会在控制台中出现错误),但是每次都会看到一个灰色框-即使我将google.maps.LatLng的值更改为实数,而不是上方的角度值。 What am I doing wrong? 我究竟做错了什么? Thanks for any help. 谢谢你的帮助。

Since i cannot comment on your answer to ask your further clarifications i assume that there is no error but there is complete grey area in your map. 由于我无法评论您的回答以要求您进一步澄清,因此我认为没有错误,但是地图上有完整的灰色区域。

Add this code after your map gets loaded. 地图加载后添加此代码。

google.maps.event.trigger(map, 'resize');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM