试图绘制多段线导致错误C#Web应用程序 [英] Trying To Draw polyline Resulting in Error C# Web App
本文介绍了试图绘制多段线导致错误C#Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制折线,但是在重载方法中有一些错误,我无法得到它为什么导致错误,当我正确地做它时...我的代码,
private void BuildScript(DataTable tbl)
{
String Locations =;
String locations =;
foreach(DataRow in tbl.Rows)
{
//绕过空行
if(r [Latitude]。ToString()。Trim()。Length = = 0)
continue;
字符串Latitude = r [Latitude]。ToString();
string Longitude = r [Longitude]。ToString();
double latitude = Convert.ToDouble(r [Latitude]);
double longitude = Convert.ToDouble(r [Longitude]);
var points = new List< GLatLng> {new GLatLng(纬度,经度)};
var polyline = new GPolyline(points);
//为此记录在地图上为标记创建一行JavaScript
Locations + = Environment.NewLine +map.addOverlay(new GMarker(new GLatLng(+ Latitude +,+ Longitude + )));;
locations + = Environment.NewLine +map.addOverlay(new GPolyline(new GLatLng(+ Latitude +,+ Longitude +)));;
}
//构建最终脚本
js.Text = @< script type ='text / javascript'>
function initialize(){
if(GBrowserIsCompatible()){
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(45.05,7.6667),2);
+ Locations + @
map.setUIToDefault();
}
}
< / script>;
js.Text = @< script type ='text / javascript'>
function initialize(){
if(GBrowserIsCompatible()){
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(45.05,7.6667),2);
+ locations + @
map.setUIToDefault() ;
}
}
< / script>;
$ / code>
现在它给了我脚本折线错误,
希望得到您的回复......
解决方案
GPolyline构造函数需要一个变量 List< GLatLng>
,这不是你传入的内容。
您需要创建GLatLng值作为列表:
var points = new List< GLatLng> {新的GLatLng(59.6919,17.8582),新的GLatLng(59.3030,18.0395),新的GLatLng(58.9789,17.5341)};
var polyline = new GPolyline(points,#ff0000,1);
I am trying to draw polyline but there is some error in in overloading method which i can not get why it is resulting in error when i am doing it correctly... my code,
private void BuildScript(DataTable tbl)
{
String Locations = "";
String locations = "";
foreach (DataRow r in tbl.Rows)
{
// bypass empty rows
if (r["Latitude"].ToString().Trim().Length == 0)
continue;
string Latitude = r["Latitude"].ToString();
string Longitude = r["Longitude"].ToString();
double latitude = Convert.ToDouble(r["Latitude"]);
double longitude =Convert.ToDouble(r["Longitude"]);
var points = new List<GLatLng> {new GLatLng(latitude,longitude)};
var polyline = new GPolyline(points);
// create a line of JavaScript for marker on map for this record
Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + ")));";
locations += Environment.NewLine + " map.addOverlay(new GPolyline(new GLatLng(" + Latitude + "," + Longitude + ")));";
}
// construct the final script
js.Text = @"<script type='text/javascript'>
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(45.05,7.6667), 2);
" + Locations + @"
map.setUIToDefault();
}
}
</script> ";
js.Text = @"<script type='text/javascript'>
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(45.05,7.6667), 2);
" + locations + @"
map.setUIToDefault();
}
}
</script> ";
}
now it is giving me error in script polyline does not exsis
Hopes for your reply ...
解决方案
The GPolyline constructor requires a variable of the type List<GLatLng>
and that's not what your are passing in.
You need to create your GLatLng values as a List:
var points = new List<GLatLng> { new GLatLng(59.6919, 17.8582),new GLatLng(59.3030, 18.0395),new GLatLng(58.9789, 17.5341) };
var polyline = new GPolyline(points,"#ff0000",1);
这篇关于试图绘制多段线导致错误C#Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文