user2093576
user2093576

Reputation: 3092

How to save Geofence using Javascript?

I am able to make a polygon on GoogleMap using following code:

//Function to create Polyline

function connectPoints()
{
 var point_add = []; // initialize an array
 var start = polyCoordinates[0]; // storing start point
 var end = polyCoordinates[(polyCoordinates.length-1)]; // storing end point
 // pushing start and end point to an array
 point_add.push(start);
 point_add.push(end);
 createPolyline(point_add); // function to join points

}

function createPolyline(polyC)
{
    alert(polyC);
 Path = new google.maps.Polyline({
 path: polyC,
 strokeColor: boundaryColor,
 strokeOpacity: 1.0,
 strokeWeight: 2
 });
 Path.setMap(map);
}

polyC is having the array of Lat and Longs. I need to save it in MongoDB with a fence name. Do I need to convert this array in JSON and save?

Upvotes: 1

Views: 360

Answers (1)

M Omayr
M Omayr

Reputation: 1351

You might be able to save it like it is now but you won't be able to run geospatial queries in mongodb because it uses 2dsphere indexes to store geospatial data in geoJSON format. Have a look at this 2dSphere Indexes. This is how you store coordinates with type e,g. Point, Line or Polygon

Upvotes: 2

Related Questions