/// <summary>
        /// Translate an address to a Location object, containing the latitude and
        /// the longitude of the address.
        /// </summary>
        /// <param name="address">The address to be translated</param>
        /// <returns>A Location instance</returns>
        public static Location addressToLocation(string address)
        {
            string[] coords;
            double latitude;
            double longitude;
            Location location;

            coords = GMapsAPI.addressToLatLng(address);
            latitude = double.Parse(coords[0]);
            longitude = double.Parse(coords[1]);
            location = new Location(address, latitude, longitude);

            return location;
        }
Exemple #2
0
        /// <summary>
        /// Return distance in km to another Location.
        /// </summary>
        /// <param name="other">the other location</param>
        /// <returns>the distance</returns>
        public double distance(Location other)
        {
            /** Convert angle coordinates into radians. */
            double a1 = (this.latitude* Math.PI ) / 180.0;
            double b1 = (this.longitude* Math.PI ) / 180.0;
            double a2 = (other.latitude* Math.PI ) / 180.0;
            double b2 = (other.longitude* Math.PI ) / 180.0;

            if ((a1 == 0 && b1 == 0) || (a2 == 0 && b2 == 0))
                throw new System.Exception("One of the member has no coordinates");

            int earthRadius = 6371;

            double ret = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2)) * earthRadius;

            return ret;
        }
Exemple #3
0
 public ServiceNode(string nodeName, string geoName, Location nodeLocation)
     : base(nodeName, geoName, nodeLocation)
 {
     neighbours = new List<ServiceNode>();
     localUsers = new List<UserNode>();
 }
Exemple #4
0
 public Node(string nodeName, string geoName, Location nodeLocation)
 {
     this.nodeName = nodeName;
     this.nodeGeoName = geoName;
     this.location = nodeLocation;
 }
Exemple #5
0
 public UserNode(string userName, Location nodeLocation)
     : base(userName, null, nodeLocation)
 {
 }
Exemple #6
0
 public bool contains(Location other)
 {
     return this.distance(other) < range;
 }