ASP.NET GoogleMap API

编程入门 行业动态 更新时间:2024-10-10 23:21:34
本文介绍了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

本文发布于:2023-11-10 14:29:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   ASP   API   GoogleMap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!