【问题标题】:ASP.NET Google Maps API v2 working, not v3ASP.NET Google Maps API v2 工作,而不是 v3
【发布时间】:2013-04-03 20:25:40
【问题描述】:

我一直在尝试将谷歌地图上的地图(和标记)添加到 asp.net 网络应用程序中,并让它工作。然后我发现我使用的是 GMap API v2 而不是 v3。 然后我在 v3 中再次创建了地图,但现在它不会显示。

这是我的 v3 代码:

<script type="text/javascript">
    function initialize() {
        var homeLatlng = new new google.maps.LatLng(57.048909, 9.921521); //McDonald's

        var mapOptions = {
            zoom: 10,
            center: homeLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>

而 v2:

<script type="text/javascript">
function initialize() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(57.05, 9.92), 14);
        map.setUIToDefault();
    }
}
</script>

很抱歉,如果这是重复的帖子,但我无法通过搜索找到答案。

亲切的问候, 莫温克尔

【问题讨论】:

标签: javascript asp.net google-maps


【解决方案1】:

你有错字new new。这是我的使用方法。

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">

    // Load google map
    google.load("maps", "3", { other_params: "sensor=false" });

    function initialize() {
        var homeLatlng = new google.maps.LatLng(57.048909, 9.921521);

        var mapOptions = {
            zoom: 10,
            center: homeLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var map = new google.maps.Map(document.getElementById("map-canvas"), 
           mapOptions);
    }

    google.setOnLoadCallback(initialize);
</script>

原始问题的解决方案

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
    function initialize() {
        var homeLatlng = new google.maps.LatLng(57.048909, 9.921521); //McDonald's

        var mapOptions = {
            zoom: 10,
            center: homeLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="map-canvas" style="width: 300px; height: 300px">
</div>

【讨论】:

  • 尝试从字面上复制您所写的内容,但没有运气:( javascript 放置在母版页中,而 div 本身位于内容页中,如果该信息有效?
  • 我也测试了你的代码。它在修复错字new new 后工作。我更新了答案。
  • 它有助于使用基于像素的大小。我会担心以后的反应。谢谢! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
相关资源
最近更新 更多