I’m trying to receive the coordinates of a polygon drawn by Google Maps API drawing manager.
Background
https://developers.google.com/maps/documentation/javascript/reference/polygon#Polygon.getPaths
Javascript
//add listeners
google.maps.event.addListener(drawingManager, ‘polygoncomplete’, function (polygon) {
getDrawnPolygon(polygon);
});
function getDrawnPolygon(polygon) {
//polygon we just drew is here.
var paths = polygon.getPath(); //get an array of latlng
//empty array of latlng objects
var latlngArry = [];
//loop thru the MVCArray<LatLng> and get the value, push to latlngArry
paths.getArray().forEach(function (value, index, array_x) {
console.log(” index: ” + index + ” value: ” + value);
var lat = value.lat;
var lng = value.ln;
var myLatlng = new google.maps.LatLng(lat, lng);
latlngArry.push(myLatlng);//value
});
console.log(“about to push”);
console.log(latlngArry.length);
App.frmCityView.ReceiveDrawnPolygon(latlngArry);
console.log(“done pushing”);
//ask if they are done or want more polygons.
}
C#
[WebMethod]
public void ReceiveDrawnPolygon(LatLng[] obj)
{
AlertBox.Show(obj[0].Lat.ToString());
}
The error I receive is “Object must implement IConvertible”.
I’ve tried using a dynamic as the parameter in the webmethod, and object. Nothing works. The array of LatLng is fine on the Javascript side though. I just can’t push it to the webmethod. Also, the error does not fire in the debugger, even though I am telling it to break on CLR System.InvalidCastException errors.
thanks
Andrew
Use DynamicObject[]. I tested it and it works fine. If it doesn’t work for you I’d need a small runnable test case.
There is no standard conversion in .NET between array of different types.
A better approach to this kind of scenario is to use this.fireWidgetEvent(“event name”, event data).
Thanks, this worked
public void ReceiveDrawnPolygon(DynamicObject[] obj)
{
dynamic item = obj[0];
AlertBox.Show(item.lat.ToString());
}
Luca, as I mentioned I already tried dynamic, and it throws the same error. Even an empty webmethod will throw the error.
[WebMethod]
public object ReceiveDrawnPolygon(dynamic obj)
{
return null;
}
Simply calling the webmethod causes the crash, so it seems WiseJ is panicking over the data and it is a WiseJ error
javascript classes and .NET classes are different things. Use dynamic and convert or use the properties directly. It’s not a Wisej issue.
Please login first to submit.