c#google maps api – html部分的javascript错误

我最近想用googlemap api用Visual Studio在一个简单的C#窗体中在地图上显示一些标记。

我使用“Web浏览器”组件来显示生成的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(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine("html, body, #map{"); sw.WriteLine("margin :0;"); sw.WriteLine("padding: 0;"); sw.WriteLine("height: 100%"); sw.WriteLine("}"); sw.WriteLine(""); //sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine("
"); sw.WriteLine(""); 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(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); 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-版

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

http://www.codeproject.com/Articles/793687/Configuring-the-emulation-mode-of-an-Internet-Expl 在webbrowser控件中使用最新版本的Internet Explorer

此外,您可以添加元标记

要么

在你的html页面标题部分,以强制现代版IE的渲染模式。

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

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

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

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