我想在网页上显示谷歌地图,但它显示一些错误

时间:2018-04-14 06:21:08

标签: c# asp.net google-maps google-maps-markers

解释:我想在谷歌地图上显示数据库中的数据,但是显示需要谷歌API密钥,我已经把它放在脚本标签内但仍然发生错误。我附上了default.apsx页面的代码和default.aspx .cs页面。 plaese帮我解决了这个问题。
错误:您需要设置Google Maps API密钥

my code is:
//Default.aspx


<%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script type="text/javascript" src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <cc1:GMap ID="GMap1" runat="server" Width="500px" Height="500px" />
    </div>
    </form>
</body>
</html>


//default.aspx.cs
using Subgurim.Controles;
using Subgurim.Controles.GoogleChartIconMaker;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GLatLng mainLocation = new GLatLng();
            GMap1.setCenter(mainLocation, 14);
            XPinLetter xpinLetter = new XPinLetter(PinShapes.pin_star, "H", Color.Blue, Color.White, Color.Chocolate);
            GMap1.Add(new GMarker(mainLocation, new GMarkerOptions(new GIcon(xpinLetter.ToString(), xpinLetter.Shadow()))));

            List<lOCATION> tblobj = new List<lOCATION>();
            using (MapDATAEntities dbcontext =new MapDATAEntities())

            {
                tblobj = dbcontext.lOCATIONs.Where(i => i.country.Equals("india")).ToList();   
            }
            PinIcon p;
            GMarker gm;
            GInfoWindow win;
            foreach (var i in tblobj)
            {

                p = new PinIcon(PinIcons.truck, Color.Cyan);
                gm = new GMarker(new GLatLng(Convert.ToDouble(i.lat), Convert.ToDouble(i.lng)),
                        new GMarkerOptions(new GIcon(p.ToString(), p.Shadow())));

                win = new GInfoWindow(gm, i.city + " <a href='" + i.empImg + "'>Read more...</a>", false, GListener.Event.mouseover);
                GMap1.Add(win);
            }
        }
    }
}

0 个答案:

没有答案