Receiving polygon coordinates drawn by GoogleMaps DrawingManager

Answered
0
0

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/drawinglayer#maps_drawing_tools-javascript

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

  • You must to post comments
Great Answer
0
0

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).

  • You must to post comments
0
0

Thanks, this worked

 

public void ReceiveDrawnPolygon(DynamicObject[] obj)
{
dynamic item = obj[0];
AlertBox.Show(item.lat.ToString());
}

  • You must to post comments
0
0

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

  • You must to post comments
0
0

javascript classes and .NET classes are different things. Use dynamic and convert or use the properties directly. It’s not a Wisej issue.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.