c#google maps api - html部分的javascript错误 [英] c# google maps api - javascript errors on the html part
问题描述
我最近想用googlemap api在Visual Studio中以简单的C#窗体形式在地图上显示一些标记。
我使用web浏览器组件来显示生成的html文件,其中包含来自google加自定义坐标的基本html代码。
$ b
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(//创建一个地图对象并指定要显示的DOM元素。);
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当然& callback = initMap \ );
sw.WriteLine(async defer>< / script>);
sw.WriteLine(< / body>);
sw.WriteLine(< / html>);
sw.Close();
webBrowser1.Navigate(file:///+ htmlPath);
这段代码运行良好,但是我的应用程序文本中说我的java脚本会产生错误。
您能否给我一些帮助,我不明白为什么会有这个错误,并且找到主题或代码例如很难。
感谢您阅读我。
我了解您的应用程序使用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 另外,您可以添加meta标签,如 或 在您的HTML页面部分为了迫使现代版本的IE的呈现模式。 作为一种替代解决方案,您可以考虑使用不同的Web浏览器嵌入式控件。例如,您可以查看Chromium嵌入式框架。 https://en.wikipedia.org/wiki/Chromium_Embedded_Framework 公共问题追踪器中还有一个有用的讨论: https://code.google.com/p/gmaps-api-issues/issues/detail?id=9004 I newly want to use the googlemap api to display some markers on a map in a simple C# windows form with visual studio. I use a "web browser" component to display a generated html file with the basic html code from google plus customized coordinate. This code is working good, but my application text me that java script generate errors. Can you give me some help, i don't understand why there is this error and finding topics or code exemple is hard. Thanks you for reading me. I understand your application uses Web Browser control that emulates a certain version of IE. Please note that the current release version of Maps JavaScript API doesn't support neither old IE versions nor compatibility mode. You should use supported browsers as mentioned in the document: https://developers.google.com/maps/documentation/javascript/browsersupport If you are working with WebBrowser controls, it can default to an IE 7 rendering mode:
https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version As you can see from the above article, you can write something in the registry to force the control to a newer IE version. It is recommended to specify at least version 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 Additionally, you can add the meta tags like or in your html page header section in order to force rendering mode for the modern version of IE. As an alternative solution you can consider a different web browser embedded control. For example, you can look at Chromium Embedded Framework. https://en.wikipedia.org/wiki/Chromium_Embedded_Framework There is a useful discussion in the public issue tracker as well: https://code.google.com/p/gmaps-api-issues/issues/detail?id=9004 这篇关于c#google maps api - html部分的javascript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
在网页浏览器控件中使用最新版本的Internet Explorer a>
< meta http-equiv =X-UA-Compatiblecontent =IE = EmulateIE10/>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge>
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);
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">