ASP.NET GoogleMap API [英] ASP.NET GoogleMap Api

查看:83
本文介绍了ASP.NET GoogleMap API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,当放在default.aspx页面上时,它可以完美地工作.但是,当我将其用作网站的一部分以及< asp:Content>内部时,在内容页面中.首先显示地图.但是,当单击ShowNewMap()时,我得到一个空的div.尽管出现了PoweredByGoogle和使用条款.这告诉我,新的地图对象已创建,但未正确显示.有人可以发现此代码有什么问题并为我提供帮助吗?谢谢.

Hi, I have the code below which works perfectly when put on a default.aspx page. But when i use it as part of a website, and inside the <asp:Content> in a content page. The map displays at first. But when ShowNewMap() is clicked, i get an empty div. Although PoweredByGoogle and Terms of USE is showing up. This tells me, the new map object is created but is not being displayed properly. Can someone spot what is wrong with this code and help me out? thanks.

<script type = "text/javascript">
           var locations = [
    ['Bondi Beach', -33.890542, 151.274856, 4],
    ['Coogee Beach', -33.923036, 151.259052, 5],
    ['Cronulla Beach', -34.028249, 151.157507, 3],
    ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 1]
  ];

           var map = new google.maps.Map(document.getElementById('map_canvas'), {
               zoom: 10,
               center: new google.maps.LatLng(-33.92, 151.25),
               mapTypeId: google.maps.MapTypeId.ROADMAP
           });

           var infowindow = new google.maps.InfoWindow();

           var marker, i;

           for (i = 0; i < locations.length; i++) {
               marker = new google.maps.Marker({
                   position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                   map: map
               });

               google.maps.event.addListener(marker, 'click', (function (marker, i) {
                   return function () {
                       infowindow.setContent(locations[i][0]);
                       infowindow.open(map, marker);
                   }
               })(marker, i));
           }

           function ShowNewMap() {
               // add a new point to the map
               var newLat = -34.028249;
               var newLon = 151.15750;

               var map = new google.maps.Map(document.getElementById('map_canvas'), {
                   zoom: 10,
                   center: new google.maps.LatLng(-33.92, 151.25),
                   mapTypeId: google.maps.MapTypeId.ROADMAP
               });

               marker = new google.maps.Marker({
                   position: new google.maps.LatLng(newLat, newLon),
                   map: map
               });
           }
       </script>
       </div> <!-- end of page content div -->

推荐答案

在您的ShowNewMap()中,您将创建一个新的本地范围内的地图对象,而不是使用您先前声明的页面级地图对象.

删除ShowNewMap()中的var ,仅使用map =
In your ShowNewMap() you are creating a new locally scoped map object, and not using the page level map object you declared previously.

remove the var in the ShowNewMap() and just have map =


这篇关于ASP.NET GoogleMap API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆