关于谷歌地图api开发遇到的问题

万载小笼包 2013-07-17 04:50:55
本人刚接触谷歌地图api的开发,在参考http://net.tutsplus.com/tutorials/asp-net/asp-net-ajax-server-controls-with-client-side-functionality/这个网站的代码练习的时候 遇到了一个问题 不知道怎么解决
希望有人可以告诉我 原因和处理的方法 谢谢。
提示错误是:程序集“MapControl, Version=1.0.4946.30100, Culture=neutral, PublicKeyToken=null”不包含名称为“MapControl.GoogleMap.js”的 Web 资源。
...全文
586 30 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
海洋夜之星 2013-07-23
  • 打赏
  • 举报
回复
没问题的话也要给点分嘛……
万载小笼包 2013-07-22
  • 打赏
  • 举报
回复
引用 26 楼 dahaianb 的回复:
原因已经找到,请在上面的图片上显示的MapControl项目里的AssemblyInfo.cs的文件里面的最底下加入一行代码:
[assembly: System.Web.UI.WebResource("MapControl.GoogleMap.js", "application/x-javascript")]
谢谢你的帮助~
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
dahaian@vip.qq.com
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 20 楼 dahaianb 的回复:
一般情况下是调试看看到那句代码出错的,然后跟踪下如果程序没有跳到那个引用的控件去的话就可以确认命名空间有问题了,你现在没办法下断点的话可以按F5执行调式,然后按F11单步走看看,确定哪里出问题了后就比较好排除了……
要不您给我个邮箱帐号 我把代码给您看下 不加断点 F5调试 F11也是灰色的
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
一般情况下是调试看看到那句代码出错的,然后跟踪下如果程序没有跳到那个引用的控件去的话就可以确认命名空间有问题了,你现在没办法下断点的话可以按F5执行调式,然后按F11单步走看看,确定哪里出问题了后就比较好排除了……
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 17 楼 woaizuguo 的回复:
围观
不要围观呀...求助..
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 16 楼 dahaianb 的回复:
看样子好像是命名空间有点问题的啊,你检查看看是不是命名空间不一致?还有你那错误是编译的时候报的错误还是调试运行的时候报的错?
额 弱弱的问下 如何检查命名空间不一致...我看了下发现不了哪里的命名空间有问题 这个程序编译的时候成功,调试运行的时候报错的
se7en 2013-07-19
  • 打赏
  • 举报
回复
围观
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
看样子好像是命名空间有点问题的啊,你检查看看是不是命名空间不一致?还有你那错误是编译的时候报的错误还是调试运行的时候报的错?
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 12 楼 dahaianb 的回复:
调试下看出错在哪里,把那代码发出来看看
这个是ajax服务器控件的代码 GoogleMap.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace MapControl
{
    /// <summary>
    /// ServerControl1 的摘要说明
    /// </summary>
    public class GoogleMap : WebControl,IScriptControl
    {
        private int _Zoom = 8;
        /// <summary>
        /// Gets or sets a value representing the zoom of the map.
        /// </summary>
        public int Zoom
        {
            get { return this._Zoom; }
            set { this._Zoom = value; }
        }

        /// <summary>
        /// Gets or sets the latitude value of the initial center point on the map.
        /// </summary>
        public double CenterLatitude { get; set; }

        /// <summary>
        /// Gets or sets the longitude value of the initial center point on the map.
        /// </summary>
        public double CenterLongitude { get; set; }

        private ScriptManager sm;

        public GoogleMap()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (!this.DesignMode)
            {
                // Test for ScriptManager and register if it exists
                sm = ScriptManager.GetCurrent(Page);

                if (sm == null)
                    throw new HttpException("A ScriptManager control must exist on the current page.");

                sm.RegisterScriptControl(this);
            }

            base.OnPreRender(e);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!this.DesignMode)
                sm.RegisterScriptDescriptors(this);

            base.Render(writer);
        }

        public IEnumerable<ScriptDescriptor>  GetScriptDescriptors()
        {
            ScriptControlDescriptor descriptor = new ScriptControlDescriptor("MapControl.GoogleMap", this.ClientID);
            descriptor.AddProperty("zoom", this.Zoom);
            descriptor.AddProperty("centerLatitude", this.CenterLatitude);
            descriptor.AddProperty("centerLongitude", this.CenterLongitude);
            yield return descriptor;
        }

        // 生成脚本引用
        public IEnumerable<ScriptReference> GetScriptReferences()
        {
            yield return new ScriptReference("MapControl.GoogleMap.js", this.GetType().Assembly.FullName);
        }
    }
}
这个是GoogleMap.js
/// <reference name="MicrosoftAjax.js"/>


Type.registerNamespace("MapControl");

MapControl.GoogleMap = function (element) {
    MapControl.GoogleMap.initializeBase(this, [element]);

    this._zoom = null;
    this._centerLatitude = null;
    this._centerLongitude = null;
    //    this._markers = null;

    this._mapObj = null;
}

MapControl.GoogleMap.prototype = {
    initialize: function () {
        MapControl.GoogleMap.callBaseMethod(this, 'initialize');

        // 在此处添加自定义初始化
        this.createMap();
    },
    dispose: function () {
        //在此处添加自定义释放操作
        MapControl.GoogleMap.callBaseMethod(this, 'dispose');
    },
    get_zoom: function () {
        return this._zoom;
    },
    set_zoom: function (value) {
        if (this._zoom !== value) {
            this._zoom = value;
            this.raisePropertyChanged("zoom");
        }
    },
    get_centerLatitude: function () {
        return this._centerLatitude;
    },
    set_centerLatitude: function (value) {
        if (this._centerLatitude !== value) {
            this._centerLatitude = value;
            this.raisePropertyChanged("centerLatitude");
        }
    },
    get_centerLongitude: function () {
        return this._centerLongitude;
    },
    set_centerLongitude: function (value) {
        if (this._centerLongitude !== value) {
            this._centerLongitude = value;
            this.raisePropertyChanged("centerLongitude");
        }
    },
    createMap: function () {
        // Set the center point, zoom, and type of map
        var centerPoint = new google.maps.LatLng(this.get_centerLatitude(), this.get_centerLongitude());
        var options = {
            zoom: this.get_zoom(),
            center: centerPoint,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        // Create the map, using the above options
        this._mapObj = new google.maps.Map(this._element, options);
    } 
}
    MapControl.GoogleMap.registerClass('MapControl.GoogleMap', Sys.UI.Control);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
这个是ASP.NET网站Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MapControlTest._Default" %>

<%@ Register Namespace="MapControl" TagPrefix="mc" Assembly="MapControl" %>
<!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 runat="server">
    <title></title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    </asp:ScriptManager>
    <div>
    <mc:GoogleMap ID="GoogleMap1" runat="server" CenterLatitude="36.1658" CenterLongitude="-86.7844"
            Width="500" Height="500">
            </mc:GoogleMap>
    </div>
    </form>
</body>
</html>
就是这三部分代码
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
调试下看出错在哪里,把那代码发出来看看
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 10 楼 dahaianb 的回复:
你查看下成功例子的webconfig有没有添加对mapcontrol的引用,有的话照着他那样的方法也添加进去

我发现成功例子的webconfig东西很少


但是我自己写的例子的webconfig多出了好多 这问题到底出在哪..
<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表可以在
machine.config.comments 中找到,该文件通常位于
\Windows\Microsoft.Net\Framework\vx.x\Config 中
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 可将调试符号插入到
已编译的页面。由于这会
影响性能,因此请仅在开发过程中将此值
设置为 true。
-->
<compilation debug="false">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
通过 <authentication> 节可以配置
安全身份验证模式,ASP.NET
使用该模式来识别来访用户身份。
-->
<authentication mode="Windows"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节
可以配置相应的处理步骤。具体而言,
开发人员通过该节可配置要显示的 html 错误页,
以代替错误堆栈跟踪。

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
system.webServer 节是在 Internet Information Services 7.0 下运行 ASP.NET AJAX
所必需的。对早期版本的 IIS 来说则不需要此节。
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
你查看下成功例子的webconfig有没有添加对mapcontrol的引用,有的话照着他那样的方法也添加进去
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 7 楼 dahaianb 的回复:
那是版本问题吧,你右击那个mapcontrol 的dll属性看下版本是哪个版本的,是编译的时候报这个错误么?调式运行的时候在哪句报的错?
调试和编译的时候都报这样的错误 还有就是我对比了正确的例子 发现webconfig不一样 这是我的webconfig 这个是可以运行的成功例子的webconfig 加断点的话 我都不知道该加到哪
cpeng123 2013-07-19
  • 打赏
  • 举报
回复
本来想回答你的,刚做了google地图api的,然后看你找到原因了,自己结贴哈
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
原因已经找到,请在上面的图片上显示的MapControl项目里的AssemblyInfo.cs的文件里面的最底下加入一行代码:
[assembly: System.Web.UI.WebResource("MapControl.GoogleMap.js", "application/x-javascript")]

万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 24 楼 dahaianb 的回复:
晕,要不你把那程序当资源发到你的csdn资源里,在我地址给我我去下载看看,因为现在完全上不了其他的网站……
你好,我把它发布成资源了,麻烦你帮我看一下,谢谢 http://download.csdn.net/detail/i_popular/5783809
海洋夜之星 2013-07-19
  • 打赏
  • 举报
回复
晕,要不你把那程序当资源发到你的csdn资源里,在我地址给我我去下载看看,因为现在完全上不了其他的网站……
万载小笼包 2013-07-19
  • 打赏
  • 举报
回复
引用 22 楼 dahaianb 的回复:
dahaian@vip.qq.com
你好,我发了两封邮件到你邮箱...
加载更多回复(8)

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧