Bit of a doozy here. I've got various COM exposed systems and I've implemented Google maps (v3) into my .net software. What I'm trying to do now, is that when a user edits a polygon (defining an area), I send back all path points to .net for storing into our database.
My problem is that .Net knows that the JS array I pass back is X elements in size, but for the life of me I can't figure out how to reference the values while iterating through the array.
Here's the .NET (VB) method I'm using from JS with window.external
Public Sub AreaPointMoved(ByRef obj As Object, ByVal s As String)
MsgBox(s) ' contains a string of lat/lngs from JS
MsgBox(obj.length)
For i As Integer = 0 To obj.length
MsgBox(obj(i).lat & ", " & obj(i).lng) ' this doesn't work
'MsgBox(obj.lat & ", " & obj.lng) ' this doesn't work
Next
End Sub
And the JS that's sending stuff back upon the set_at
event being triggered:
function DrawAreaOverlay(area, col)
{
var coordsString = "";
var areaCoords = [];
overlayLayer[overlayCount] = new Array();
for(var j=0; j<area.Count; j++)
{
areaCoords.push(new google.maps.LatLng(area.Item(j).lng, area.Item(j).lat));
}
var poly = new google.maps.Polygon({
paths: areaCoords,
strokeColor: col,
strokOpacity: 0.35,
strokeWeight: 2,
fillColor: col,
fillOpacity: 0.25,
geodesic: false,
editable: canEdit,
draggable: canDrag,
map: map
});
overlayLayer[overlayCount].push(poly);
poly.getPaths().forEach(function(path, index){
google.maps.event.addListener(path, 'set_at', function(){
var arrayOfPoints = new Array();
var g = new Array();
arrayOfPoints = poly.getPath();
coordsString = "";
for(var i=0; i<arrayOfPoints.length; i++)
{
//simpleArray[i] = poly.getPath().getAt(i).lat() + ", " + poly.getPath().getAt(i).lng();
geoObj = new Object();
geoObj.lat = poly.getPath().getAt(i).lat();
geoObj.lng = poly.getPath().getAt(i).lng();
g.push(geoObj);
coordsString += poly.getPath().getAt(i).lat() + ", " + poly.getPath().getAt(i).lng() + "|";
}
window.external.AreaPointMoved(g, coordsString);
//alert(path.getLength());
});
});
}
I'm really confused. Getting objects from .net to JS was a doddle. But I can't for the life of me figure out what I'm doing wrong on the reverse :(
Cheers.