public CartoPlaceData ParsePlace(string place) { var p = new CartoPlaceData(); p.Name = place; var index = place.LastIndexOf(','); if (index > 0) { var name = place.Substring(0, index).Trim(); var countryCode = place.Substring(index + 1).Trim(); var country = GeoCountryInfo.ByISO(countryCode); if (country != null) { p.Name = name; p.Country = country.Name; index = name.LastIndexOf(','); if (index > 0) { var area = name.Substring(index + 1).Trim(); name = name.Substring(0, index).Trim(); if (country.HasRegions) { var region = GeoRegionInfo.ByISO(country.ISO2, area); if (region != null) { p.Region = region.RegionName; p.Name = name; } else { p.Locality = area; p.Name = name; } } else { p.Locality = area; p.Name = name; } } } } return(p); }
public void GeoRegionInfo_ByISO() { var r = GeoRegionInfo.ByISO("uS-Md"); Assert.AreEqual("MD", r.RegionAbbr); Assert.AreEqual(840, r.Country.CountryID); }