1public void GPSModel(string x, string y, string ss)//动态地图文件 2 { 3 if (x.Contains("-") && y.Contains("-")) return; 4 if (x=="" ||y=="") return; 5 StringBuilder IndexHTMLBuilder = new StringBuilder(); 6 IndexHTMLBuilder.Append("<!DOCTYPE html>" + Environment.NewLine); 7 IndexHTMLBuilder.Append("<html>" + Environment.NewLine); 8 IndexHTMLBuilder.Append("<head>" + Environment.NewLine); 9 IndexHTMLBuilder.Append("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=gb2312\"/>" + Environment.NewLine); 10 IndexHTMLBuilder.Append("<title>baidumap</title> " + Environment.NewLine); 11 IndexHTMLBuilder.Append("<script type=\"text/javascript\" src=\"http://api.map.baidu.com/api?v=1.3\"></script>" + Environment.NewLine); 12 IndexHTMLBuilder.Append("</head>" + Environment.NewLine); 13 IndexHTMLBuilder.Append("<body>" + Environment.NewLine); 14 IndexHTMLBuilder.Append("<div style=\"width: 600px; height:1000px; border:1px solid gray\" id=\"container\"></div>" + Environment.NewLine); 15 IndexHTMLBuilder.Append("</body>" + Environment.NewLine); 16 IndexHTMLBuilder.Append("</html>" + Environment.NewLine); 17 IndexHTMLBuilder.Append("<script type=\"text/javascript\">" + Environment.NewLine); 18 IndexHTMLBuilder.Append("var map = new BMap.Map(\"container\");" + Environment.NewLine); 19 IndexHTMLBuilder.Append("var point = new BMap.Point(" + y + "," + x + ");" + Environment.NewLine); 20 IndexHTMLBuilder.Append("map.centerAndZoom(point, 15);" + Environment.NewLine); 21 IndexHTMLBuilder.Append("map.enableScrollWheelZoom(); " + Environment.NewLine); 22 IndexHTMLBuilder.Append("map.enableKeyboard(); " + Environment.NewLine); 23 IndexHTMLBuilder.Append("var point2 = new BMap.Point(" + y + "," + x + ");" + Environment.NewLine); 24 IndexHTMLBuilder.Append("var marker2 = new BMap.Marker(point2);" + Environment.NewLine); 25 IndexHTMLBuilder.Append("map.addOverlay(marker2);" + Environment.NewLine); 26 IndexHTMLBuilder.Append("var label2 = new BMap.Label(\"" + ss + "\",{offset:new BMap.Size(20,-10)});" + Environment.NewLine); 27 IndexHTMLBuilder.Append("marker2.setLabel(label2);" + Environment.NewLine); 28 IndexHTMLBuilder.Append("</script>" + Environment.NewLine); 29 string Htmltext = IndexHTMLBuilder.ToString(); 30 System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory , Htmltext, Encoding.UTF8); 31 }
使用方法:x,y,ss 分别对应经纬度,Mark点名称,动态生成Html文件,可以在浏览器预览。