Reputation: 149
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 ...
Upvotes: 0
Views: 944
Reputation: 31404
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);
Upvotes: 1