c# Example of Geofencing

Last post 10/20/2009 6:58:27 PM by Chris Pietschmann. 6 replies. << Back to Web.Maps.VE v2.0 General
3/10/2009 1:45:58 PM
mobchase

c# Example of Geofencing

Anyone have a C# exampl eof geofencing? I want to just create circles based upon a click and scale out. -rich
3/13/2009 3:46:02 AM
Chris Pietschmann

Re:c# Example of Geofencing

Could you please elaborate on what you want to do? Do you just want to draw a circle around the point the user clicks?
3/13/2009 4:24:22 AM
mobchase

Re:c# Example of Geofencing

sorry should have put some detail into it... ok

I need to be able to draw a circle from the point where a user clicks on the map.  get the lat/long and radius when the user saves it so I can calculate it when checking the geofence.  I would also like them to be able to move the circle and resize if possible.  I've investigated some javascript options but it gets very complicated for a simple task.

-rich

3/18/2009 12:27:36 PM
mobchase

Re:c# Example of Geofencing

Any ideas on how we could go about this?  I'm a little stuck here... I've tried several javascript solutions but they just don't work as I expected it to...

-rich

3/19/2009 8:45:29 PM
Chris Pietschmann

Re:c# Example of Geofencing

What you describe can be implemented, but you will need to write a little code to make it work. Plotting a circle at the point where a user clicks can be done from within server-side code using the Web.Maps.VE control. You can also move and resize the drawn circle from server-side code.

You will need to write a little code to do the actual math for calculating the incremental points for the circle to be plotted. Here's a blog post that contains a javascript function for calculating the points that could easily be converted to C# or VB.NET for server-side use: http://pietschsoft.com/post/2008/02/Virtual-Earth-Draw-a-Circle-Radius-Around-a-LatLong-Point.aspx

As far as moving the position of the Shape; if you want to allow the user to reposition the Shape by clicking and dragging the mouse; this can't be done from server-side code, but the Virtual Earth Toolkit I started last fall contains a small "extender" control written in JavaScript that allows you easily make Shapes draggable.  http://vetoolkit.codeplex.com/

Using the Virtual Earth Toolkit stuff with Web.Maps.VE is actually very simple; all you need to do is get a reference to the underlieing VEMap object in the Control. You can do this by executing the Web.Maps.VE Controls "get_Map" JavaScript API method.

var map = $find('<%=Map1.ClientID%>').get_Map();

If you have any additional questions, please ask.

--
Chris Pietschmann
10/13/2009 1:27:17 AM
hkhokhar12

Re:c# Example of Geofencing

Hi Chris,

I managed to find a very nice example which allows to create circle on the map.
Link: http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/c0e4133f-2825-4fa1-8f68-44c6bdf5ae21

The example is using javascript and I was wondering if its possible to integrate or use the above example with Web.Maps.VE control.

I did try referencing the map control in the above example to my Maps.VE control but it doesnt seem to trigger the mouseup,mousedown events.

Any help will be greatly appriciated.

Thanks in advance,

Haroon
10/20/2009 6:58:27 PM
Chris Pietschmann

Re:c# Example of Geofencing

You'll want to use the Maps "OnClick" event, then when the event fires you can add a Shape of type polygon that has it's collection of LatLong points set to the calculated values to make up a circle.

Here's an example in JavaScript that I wrote a while back to calculate the necessary points to plot a circle on the Map. This code wont be too difficult to convert to .NET (C# / VB.NET) since it's mostly just math functions.

http://pietschsoft.com/post/2008/02/09/Virtual-Earth-Draw-a-Circle-Radius-Around-a-LatLong-Point.aspx