public static PointLatLng ParsePointFromString(string pos) { PointLatLng point = new PointLatLng(); CoordinateSharp.Coordinate c; if (CoordinateSharp.Coordinate.TryParse(pos, out c)) { point.Lat = c.Latitude.ToDouble(); point.Lng = c.Longitude.ToDouble(); } else { GeorefCoordinate georef; if (GeorefCoordinate.TryParse(pos, out georef)) { point.Lat = georef.Latitude; point.Lng = georef.Longitude; } else { try { string[] arr = pos.Split(','); point.Lat = Convert.ToDouble(arr[0]); point.Lng = Convert.ToDouble(arr[1]); } catch (Exception) { point = new PointLatLng(); } } } return(point); }
public static bool TryParse(string georef, out GeorefCoordinate coordinate) { Regex regex = new Regex(@"([ABCDEFGHJKLMNPQRSTUVWXYZ]{1})([ABCDEFGHJKLM]{1})([ABCDEFGHJKLMNPQ]{2})(\d+)"); Match match = regex.Match(georef); if (match.Success) { coordinate = new GeorefCoordinate(georef); return(true); } else { coordinate = null; return(false); } }