I am trying to add multiple markers to a google map. The data comes from C# WPF.
Here is the C# code:
private void Button_click(object sender, RoutedEventArgs e)
{
int[] lat = { 10, 30, 50, 70 };
int[] lon = { 10, 30, 50, 70 };
webBrowser1.InvokeScript("addMarker", new object[] { lat, lon });
}
Here is the javascript function embedded in a local html file:
function addMarker(Lat,Long) {
for (var i=0;i<Lat.length; i++){
var latLng = new google.maps.LatLng(Lat[i],Long[i]);
var marker = new google.maps.Marker({
position: latLng,
title: 'Hello World!',
map: map
});
}
} // end of addMarker
When I compiled this program with VS 2015 and clicked the button to invoke this js script, I always got an error message telling me that a function is expected in this line right after 'var'
for (var i=0;i<Lat.length; i++){
The exception report by VS is like this: System.Runtime.InteropServices.COMException Exception from HRESULT: 0x80020101 and the location of the exception is right here:
webBrowser1.InvokeScript("addMarker", new object[] { lat, lon });
I am very new to Javascript programming. Please help.