谷歌地图Api不显示图像

问题描述:

我在asp.net中执行谷歌地图API有问题。这里是我的aspx代码:谷歌地图Api不显示图像

<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeFile="visual_loc.aspx.cs" Inherits="visual_loc" %> 



<%--A sample project by Ghaffar khan--%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"> 
    <title>Your Data on Google Map </title> 
    <%--Google API reference--%> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false 
       &amp;key=asdfg" type="text/javascript"> 
    </script> 
</head> 

<body onload="initialize()" onunload="GUnload()"> 
    <form id="form1" runat="server"> 
    <asp:Panel ID="Panel1" runat="server"> 
       <%--Place holder to fill with javascript by server side code--%> 
       <asp:Literal ID="js" runat="server"></asp:Literal> 
       <%--Place for google to show your MAP--%> 
       <div ID="map_canvas" style="width: 100%; height: 728px; margin-bottom:      2px;"> 
       </div> 
       <br /> 
      </asp:Panel> 
     <br /> 
    </form> 
    </body> 

</html> 

而且我后面的代码:
getLocation()是后者从我的数据库中的经度和纬度的方法。 createDataTable()是从这些位置创建DataTable的方法。

protected void Page_Load(object sender, EventArgs e) 
    { 
     string user_id; 
     user_id = Request.Cookies["cookie"]["Login"]; 
     getLocation(user_id); 
     BuildScript(createDataTable()); 

    } 
    private void BuildScript(DataTable tbl) 
    { 
     String Locations = ""; 
     foreach (DataRow r in tbl.Rows) 
     { 
      // bypass empty rows   
      if (r["Latitude"].ToString().Trim().Length == 0) 
       continue; 

      string Latitude = r["Latitude"].ToString(); 
      string Longitude = r["Longitude"].ToString(); 

      // create a line of JavaScript for marker on map for this record  
      Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + ")));"; 
     } 

     // construct the final script 
     js.Text = @"<script type='text/javascript'> 
          function initialize() { 
           if (GBrowserIsCompatible()) { 
           var map = new GMap2(document.getElementById('map_canvas')); 
           map.setCenter(new GLatLng(52.259, 21.012), 2); 
           " + Locations + @" 
           map.setUIToDefault(); 
           } 
          } 
          </script> "; 
    } 

整个操作导致显示没有内容的空白网站。我究竟做错了什么?

+0

这可能是在你的情况矫枉过正,但我​​发现通过JSON反馈位置是一个更干净的方式来做到这一点,并提供良好的定制。如果感兴趣,我可以添加代码。 – MikeSmithDev

+0

你在localhost上还是在域上运行这个?如果在某个域上,您确实有相应的密钥? https://developers.google.com/maps/signup自2010年5月以来,** v2 API **已被弃用**。 – Jacco

+0

是的,我确实有有效的钥匙,而且我在本地主机上托管它,迈克你能告诉我另一种选择吗?Ghaffar汗 – Grzzzzzzzzzzzzz

问题是我做了错误的目录到我的标记,所以无法在地图上看到。一旦我输入有效的目录一切正常。