English 中文(简体)
ASP.net 谷歌地图
原标题:ASP.net Google Maps

我试图在伙伴关系中增加一个 go图。 净儿童页(有主页)。 地图上的信息似乎从山洞中排出,但我看不到什么。 当我击中神学院的F12时,我可以看到,我的四分之四已经填满了有关地图的许多其他干.和数据。

我为何看不出任何想法?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Contact.aspx.cs" Inherits="CentralWebsite.Contact" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        .style1
        {
            width: 317px;
        }
    </style>
    <script type="text/javascript"
      src="http://maps.googleapis.com/maps/api/js?key=mykey=false">
    </script>
    <script type="text/javascript">
        function initialize() {
            var myOptions = {
                center: new google.maps.LatLng(-34.397, 150.644),
                zoom: 8,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
            alert("alert " + document.getElementById("map_canvas"));
        }
    </script>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <table style="width: 100%;">
        <tr>
            <td class="style1">
                <h1>Telephone: 01709</h1>
                <h1>Address</h1>
                <h3></h3>
                <h3>Rotherham</h3>
                <h3>South Yorkshire</h3>
                <h3>S60 1PP</h3>
            </td>
            <td>
                <div id="map_canvas" style="width:100%; height:100%">
                    map should go here
                </div>
            </td>
        </tr>
    </table>

</asp:Content>

我称之为初始功能,把这一功能作为主页的上载特性如下:

 public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HtmlGenericControl myBody = (HtmlGenericControl)Master.FindControl("myBody");
            myBody.Attributes.Add("onload", "initialize()");
        }
    }

Many thanks

页: 1

问题回答

在主页上,你应打上“米波迪”和“服务器”的标签。

这是因为你没有在任何地方打上“<>条/条码>!

把它放在纸面上,或放在单面上,或在地图四点之后叫它。

<div id="map_canvas" style="width:100%; height:100%">map should go here</div>
<script>initialize();</script>

或更糟的是,在表尾载有四面地图

</table>
    <script>initialize();</script>

首先,它喜欢使用你钥匙的复印件第2版。 3. 第二,我利用J Query来称先天,而不是在编码背后增加属性,似乎有 b,我与它斗争,让它重新工作。

Try like this (I have local reference to JQuery specified, adjust if necessary)

<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
    $(function () {
        initialize();
    });


    function initialize() {
        var myOptions = {
            center: new google.maps.LatLng(-34.397, 150.644),
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
        alert("alert " + document.getElementById("map_canvas"));
    }
</script>

Also, in css explicitly set height/width for the map_canvas:

#map_canvas
{
    width: 300px;
    height: 265px;
    border:1px solid #C3C8BD;
    border-radius:5px;
    -o-border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
}

。 你们可以通过使用F12开发商工具或火力分析来核实这一百分比使地图四的高度达到零。

这部法典显示一个地图四,作为浏览器转成。 注:java字母载于~/bundles/gmaps>上。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testme.aspx.cs" Inherits="drawingTools.testme" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=false&libraries=drawing"></script>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">
        <%: System.Web.Optimization.Scripts.Render("~/bundles/gmaps") %>
        <script type="text/javascript">
            google.maps.event.addDomListener(window,  load , myPageLoad);
        </script>
    </asp:PlaceHolder>
</head>
<body>
    <form runat="server">        
        <div id="map_canvas" class="map_canvas" >
        </div>
    </form>
</body>
</html>

In the aspx code google.maps.event.addDomListener(window, load , pageLoad); serves to invoke the myPageLoad function when the window has loaded. Or use the JQuery $(document).ready function to wait for the document to be ready for google maps initialization.

function myPageLoad() {
    resize();  
    initialize(); // your google.map initializer
}

The resize( function used for resizablemap. 根据要求,你可以 t击。 目的是确定<代码>>_canvas div to 100%。

function resize() {
  var main = document.getElementById("map_canvas");
  main.style.height = (getWindowHeight()) + "px";
  main.style.width = (getWindowWidth()) + "px";
}
onresize = function () { resize(); };

j印功能,getWindowHala()和getWindowWidth(,可以从许多来源获得,或可从你自己书写。

As an editorial aside, using google maps on aspx pages presents challenges. E.g. a postback from a button control will invoke the myPageLoad function when not desired with bad results, unless the postback is disabled.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签