1

我正在自学asp .net mvc 3。我阅读了本教程: http: //www.codeproject.com/Articles/148949/ASP-NET-MVC-3-the-Razor-View-Engine-and-Google-Map和其他几个这样的帖子。但是,我无法在我的应用程序上运行谷歌地图。我究竟做错了什么?

看法:

    @section Scripts_head {
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
    }

    <script type="text/javascript">
        function initialize() {
            var latlng = new google.maps.LatLng(40.716948, -74.003563);
            var options = { zoom: 14, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };
            var map = new google.maps.Map(document.getElementById("map"), options);
        }

        $(function () {
            initialize();
        });
    </script>
<div id="map" style="width:80%; height:80%"></div>

我也尝试将 div 放在 script 标签上。

布局页面:

<head>
    ...
    @RenderSection("Scripts_head", false)
</head>

控制器:

public class MapController : Controller
{
    //
    // GET: /Map/

    public ActionResult Index()
    {
        return View();
    }

}
4

2 回答 2

1

如果您没有错误,那么它可能是您的 div“地图”的大小。这是您在 JsFiddle 中提取和工作的代码:http: //jsfiddle.net/GNwU8/3/

于 2012-08-25T00:08:07.327 回答
0

给你地图 div 一个绝对大小。你有:

<div id="map" style="width:80%; height:80%"></div>

...但那是什么的 80%?

而是尝试:

<div id="map" style="width:400px; height:300px"></div>
于 2012-08-25T08:32:21.010 回答