开发者

google maps inside my Web Content Form within Master Page

开发者 https://www.devze.com 2023-04-06 09:02 出处:网络
I am trying to add a simple Google Map to my Web Content Form (that uses a Master Page) but nothing is showing up and I\'m not getting any noticeable errors

I am trying to add a simple Google Map to my Web Content Form (that uses a Master Page) but nothing is showing up and I'm not getting any noticeable errors

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="ShelterMap.aspx.cs" Inherits="ShelterExpress.ShelterMap" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<style type="text/css"> 
  #map_canvas { height: 100% } 
</style> 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js "></script> 
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script> 
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<div id="map_canvas" style="width:100%; height:100%"></div> 

<script type="text/javascript">
    $(document).ready(function() {
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
            zoom: 8,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMA开发者_StackOverflow社区P
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    });
</script>

</asp:Content>


You need to set width and height explicity, instead of 100%. Remove <style></style> tag, and set <div id="map_canvas" style="width: 300px; height: 300px">

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js "></script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="map_canvas" style="width: 300px; height: 300px">
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        }); 
    </script>
</asp:Content>

google maps inside my Web Content Form within Master Page


The map is loading but you have a 0px height div once it has loaded because (without seeing because you didn't post master page code) I would imagine you have not set the html body tag to have a 100% height as well as the html tag.

It gets confused and cannot figure its own height out therefore you end up with a zero height div where the map should be.

Try setting the #map_canvas to have a fixed height (say 600px) or make both body & html attributes also have a 100% height css rule.

Should fix the issue.


<div id="map_canvas" style="position:absolute;top:0;bottom:0;left:0;right:0;">
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号