C#Google Maps api-HTML部分的javascript错误 - javascript

我最近想使用googlemap API在带有Visual Studio的简单C#Windows窗体中在地图上显示一些标记。

我使用“网络浏览器”组件来显示生成的html文件,其中包含来自google的基本html代码以及自定义坐标。

        const string htmlPath = "D:/map.html";
        StreamWriter sw = new StreamWriter(htmlPath, false, System.Text.Encoding.GetEncoding(437));

        string centerLongitude = centerLongitudeTextBox.Text;
        string centerLatitude = centerLatitudeTextBox.Text;




        sw.WriteLine("<!DOCTYPE html>");
        sw.WriteLine("<html>");

        sw.WriteLine("<head>");
        sw.WriteLine("<meta charset=\"utf-8\">");

        sw.WriteLine("<style>");
        sw.WriteLine("html, body, #map{");
        sw.WriteLine("margin :0;");
        sw.WriteLine("padding: 0;");
        sw.WriteLine("height: 100%");
        sw.WriteLine("}");
        sw.WriteLine("</style>");

        //sw.WriteLine("<link rel=\"stylesheet\" href=\"/maps/documentation/javascript/demos/demos.css\">");
        sw.WriteLine("</head>");

        sw.WriteLine("<body>");

        sw.WriteLine("<div id=\"map\"></div>");

        sw.WriteLine("<script>");
        sw.WriteLine("function initMap() {");
        sw.WriteLine("// Create a map object and specify the DOM element for display.");
        sw.WriteLine("var map = new google.maps.Map(document.getElementById('map'), {");
        sw.WriteLine("center: { lat: "+ centerLatitude +", lng: "+ centerLongitude +"},");
        sw.WriteLine("scrollwheel: false,");
        sw.WriteLine("zoom: 8");
        sw.WriteLine("});");
        sw.WriteLine("}");
        sw.WriteLine("</script>");

        sw.WriteLine("<script src=\"https://maps.googleapis.com/maps/api/js?key=MYKEY of course&callback=initMap\"");

        sw.WriteLine("async defer></script>");

        sw.WriteLine("</body>");

        sw.WriteLine("</html>");
        sw.Close();

        webBrowser1.Navigate("file:///" + htmlPath);

这段代码运行良好,但是我的应用程序发短信说Java脚本生成错误。

您能给我些帮助吗,我不明白为什么会出现此错误,并且很难找到主题或代码示例。

谢谢您阅读我。

Error

参考方案

我了解您的应用程序使用Web浏览器控件来模拟IE的特定版本。

请注意,当前的Maps JavaScript API版本不支持旧的IE版本,也不支持兼容模式。您应该使用文档中提到的受支持的浏览器:

https://developers.google.com/maps/documentation/javascript/browsersupport

如果您正在使用WebBrowser控件,则它可以默认为IE 7呈现模式:
https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

从上面的文章中可以看到,您可以在注册表中编写一些内容以将控件强制为较新的IE版本。建议至少指定版本10。

http://www.codeproject.com/Articles/793687/Configuring-the-emulation-mode-of-an-Internet-Expl
Use latest version of Internet Explorer in the webbrowser control

此外,您可以添加meta标签,例如

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10" />

要么

<meta http-equiv="X-UA-Compatible" content="IE=edge">

在您的html页面标题部分中,以强制为现代版本的IE呈现模式。

作为替代解决方案,您可以考虑使用其他Web浏览器嵌入式控件。例如,您可以看一下Chromium嵌入式框架。

https://en.wikipedia.org/wiki/Chromium_Embedded_Framework

在公共问题跟踪器中也有一个有用的讨论:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=9004

HTTP 405 API jQuery Ajax PHP - javascript

我正在尝试在myewellness.com上添加成员我在wordpress网站上使用jquery和php,我必须收集用户的详细信息并将其添加到myewellness.com这是他们api文档的链接:http://www.mediafire.com/view/pr6s7isht9ihdao/API-Services-Documentation-v2.0-1.p…

重复使用Google Api Bearer令牌来访问用户的云端硬盘 - javascript

我有以下几点: gapi.auth.authorize( { client_id: CLIENT_ID, scope: SCOPES, immediate: false }, handleAuthResult); 这使我可以访问access_token:目标是使该应用程序的用户可以授予对我的应用程序的访问权限,以使用其Google驱动器存储其内容。我需要能够…

Javascript-从当前网址中删除查询字符串 - javascript

单击提交按钮后,我需要从网址中删除查询字符串值。我可以用jQuery做到这一点吗?当前网址:siteUrl/page.php?key=value 页面提交后:siteUrl/page.php 实际上,我已经从另一个带有查询字符串的页面着陆到当前页面。我需要在页面首次加载时查询字符串值以预填充一些详细信息。但是,一旦我提交了表格,我就需要删除查询字符串值。我已…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

如何在JQuery中操作JSONArray - javascript

我有一个php函数,它以JSON返回此代码{"0":{"title":"Dans l\u2019appartement"},"1":{"title":"A l\u2019a\u00e9roport - D\u00e9part de B\u00e9at…