/// <summary> /// Create a clause of geo distance. /// </summary> /// <returns> /// KiiClause instance. /// </returns> /// <exception cref='ArgumentException'> /// Is thrown when an argument is invalid. Please see parameter explanation. /// </exception> /// <remarks> /// This clause inquires objects in the specified circle.<br/> /// <b>Note:</b> You can get the results in ascending order of distances from center. /// To do so, build the orderBy field by "_calculated.{specified value of calculatedDistance}" and pass it in <see cref="KiiQuery.SortByAsc()"/>.<br/> /// Note that, descending order of distances is not supported. The unit of distance is meter. /// <see cref="KiiObject"/> /// <code> /// // example /// string calculatedDistance = "distanceFromCurrentLoc"; /// KiiGeoPoint currentLoc = KiiGeoPoint(120.000,77.000); //dummy location /// KiiClause geoDist = KiiClause("location",currentLoc, 7.0,calculatedDistance); /// KiiQuery query = KiiQuery.QueryWithClause(geoDist); /// // sort distance ny ascending order. /// string orderByKey = "_calculated."+ calculatedDistance; /// query.SortByAsc(orderByKey); /// KiiBucket bucket = Kii.Bucket("MyBucket"); /// KiiQueryResult<KiiObject> result = bucket.Query(query); /// if(result.Size > 0) /// { /// KiiObject object = result[0]; /// double distanceInMeter = object.GetJsonObject("_calculated").GetDouble(calculatedDistance); /// } /// </code> /// </remarks> /// <param name='key'> /// Name of the key to inquire, which holds geo point. Must not null or empty string. /// </param> /// <param name='center'> /// Geo point which specify center of the circle. Mus not null. /// </param> /// <param name='radius'> /// Radius of the circle. unit is meter. value should be in range of 0-20000000. /// </param> /// <param name='calculatedDistance'> /// Calculated distance is used for retrieve distance from the center from the query result. If the specified value is null, query result will not contain the distance. /// </param> /// public static KiiClause GeoDistance(string key, KiiGeoPoint center, double radius, string calculatedDistance) { if (Utils.IsEmpty(key)) { throw new ArgumentException("key must not null or empty string"); } if (radius <= 0 || radius > 20000000) { throw new ArgumentException("radius value should be in range of 0-20000000"); } return(GeoDistanceInternal(key, center.ToJson(), radius, calculatedDistance)); }
/// <summary> /// Create a clause of geo box. /// </summary> /// <remarks> /// This clause inquires objects in the specified rectangle. /// Rectangle would be placed parallel to the equator with specified coordinates of the corner. /// </remarks> /// <returns> /// KiiClause instance. /// </returns> /// <exception cref='ArgumentException'> /// Is thrown when an argument is invalid. Please see parameter explanation. /// </exception> /// <param name='key'> /// Name of the key to inquire, which holds geo point. Must not null or empty string. /// </param> /// <param name='northEast'> /// North east corner of the rectangle. Must not null. /// </param> /// <param name='southWest'> /// South west corner of the rectangle. Must not null. /// </param> public static KiiClause GeoBox(string key, KiiGeoPoint northEast, KiiGeoPoint southWest) { if (Utils.IsEmpty(key)) { throw new ArgumentException("key must not null or empty string"); } JsonObject box = new JsonObject(); box.Put("ne", northEast.ToJson()); box.Put("sw", southWest.ToJson()); return(GeoBoxInternal(key, box)); }
public void Test_0002_GeoPoint_Default_Constructor() { KiiGeoPoint location = new KiiGeoPoint(); Assert.AreEqual("{\"lat\":-0,\"lon\":-0,\"_type\":\"point\"}", location.ToJson().ToString()); }
public void Test_0001_GeoPoint_Valid_Parameters() { KiiGeoPoint location = new KiiGeoPoint(71.00, 102); Assert.AreEqual("{\"lat\":71,\"lon\":102,\"_type\":\"point\"}", location.ToJson().ToString()); }