public ActionResult CheckValidLocation(LocationViewModel location) { if (location != null) { if (location.Country != "Australia") { return Json(new { status = true }); } GeoIpService geoServices = new GeoIpService(); var coordinate = geoServices.GetByAddress(location.StreetNumber, location.Street, location.Postcode, location.Country, location.State); if (coordinate != null) { return Json(new { status = true }); } } return Json(new { status = false }); }
/// <summary> /// Get Position of Searcher By IP, address or gepperid /// </summary> /// <param name="searcher"></param> /// <returns></returns> public static Coordinates GetPositionSearcher(UserDto searcher) { var geoip = new GeoIpService(); Coordinates searcherCoordinates = geoip.GetByIp(); if (searcherCoordinates == null && searcher != null) { searcherCoordinates = GetLocationByUserAddress(searcher); } return searcherCoordinates; }
/// <summary> /// Get distance of an specialist /// </summary> /// <param name="searcherCoordinates"></param> /// <param name="specialist"></param> /// <returns></returns> public static double GetDistance(Coordinates searcherCoordinates, UserDto specialist) { double distance = 999999; if (searcherCoordinates != null) { var geoIp = new GeoIpService(); LocationDto location = specialist.Locations.FirstOrDefault(); Coordinates responseSpecialist = GetLocationByUserAddress(specialist); if (responseSpecialist != null) { distance = GeoHelper.Distance(searcherCoordinates, new Coordinates { Latitude = responseSpecialist.Latitude, Longitude = responseSpecialist.Longitude }, UnitsOfLength.Kilometer); } } return distance; }
/// <summary> /// Get user location follow address or geeperId /// </summary> /// <param name="user"></param> /// <returns></returns> public static Coordinates GetLocationByUserAddress(UserDto user) { var geoIp = new GeoIpService(); LocationDto location = user.Locations.FirstOrDefault(); Coordinates coordinates = new Coordinates(); if (location != null) { if (string.IsNullOrWhiteSpace(location.GeepersName)) { coordinates = geoIp.GetByAddress(location.StreetNumber, location.Street, location.Postcode, location.Country, location.State); } else { coordinates = geoIp.GetByGeepers(location.GeepersName); if (coordinates == null) { coordinates = geoIp.GetByAddress(location.StreetNumber, location.Street, location.Postcode, location.Country, location.State); } } } return coordinates; }