protected void Page_Load(object sender, EventArgs e) { List<OfficesInMap> officesWithGeoInfos = new List<OfficesInMap>(); List<OfficeListItem> offices = GetOfficesForMap(3, connString); foreach (OfficeListItem office in offices) { OfficesInMap officeWithGeo = new OfficesInMap(); officeWithGeo.Name = office.Name; officeWithGeo.Latitude = office.Latitude; officeWithGeo.Longtitude = office.Longtitude; officesWithGeoInfos.Add(officeWithGeo); } officesInMap = officesWithGeoInfos; }
//protected string officesInMap; //method 4 protected void Page_Load(object sender, EventArgs e) { //=======================method 1, 2: use c# code to get lat, lng:=================================== double lng; double lat; //int confidence; List<OfficeListItem> offices = new List<OfficeListItem>(); List<OfficesInMap> officesWithGeoInfos = new List<OfficesInMap>(); offices = getOfficesForPanel(4020, connString); foreach (OfficeListItem office in offices) { string address = office.Address1; string address2 = office.Address2; string city = office.City; string state = office.State; string zip = office.Zip; string fullAddress = address + ", " + city + ", " + state + ", " + zip; //GeoCoding.getXMLGeoCoding(address, address2, city, state, zip, out lng, out lat, out confidence); //time consuming GeoCoding.GetLatLng(fullAddress, out lat, out lng); //my google map geocode OfficesInMap officeWithGeo = new OfficesInMap(); officeWithGeo.Name = office.Name; officeWithGeo.Latitude = lat; officeWithGeo.Longtitude = lng; officesWithGeoInfos.Add(officeWithGeo); } officesInMap = officesWithGeoInfos; //=============method 3: use MapQuest to get lat, lng: some address cannot find lat/lng============== //List<OfficeListItem> officesAllDetail = getOfficesForPanel(4020, connString); //List<OfficesWithNameAddress> offices2Map = new List<OfficesWithNameAddress>(); //foreach (OfficeListItem office in officesAllDetail) //{ // OfficesWithNameAddress officewithNameAddr = new OfficesWithNameAddress(); // officewithNameAddr.Name = office.Name; // string street = office.Address1; // //string text = "841 Hospital Road, Suite 2100"; // //bool a = Regex.IsMatch(text, @"(.*Road|Street|St|Avenue).*"); // string newstreet = Regex.Match(street, @"(.*((Road)|(Street)|(Avenue)|(Lane)|(Drive))).*").Groups[1].Value; // officewithNameAddr.Street = newstreet; // officewithNameAddr.City = office.City; // officewithNameAddr.State = office.State; // officewithNameAddr.PostalCode = office.Zip; // offices2Map.Add(officewithNameAddr); //} ////offices2Map.RemoveAt(5); offices2Map.RemoveAt(4); offices2Map.RemoveAt(4); //officesInMap = offices2Map; //=====================method 4: use MapQuest to get lat, lng:==================== //List<OfficeListItem> offices = new List<OfficeListItem>(); //List<OfficesWithNameAddress> officesWithNameAddress = new List<OfficesWithNameAddress>(); //offices = getOfficesForPanel(3505, connString); //foreach (OfficeListItem office in offices) //{ // OfficesWithNameAddress officewithNameAddr = new OfficesWithNameAddress(); // officewithNameAddr.Name = office.Name; // officewithNameAddr.Street = office.Address1; // officewithNameAddr.City = office.City; // officewithNameAddr.State = office.State; // officewithNameAddr.PostalCode = office.Zip; // officesWithNameAddress.Add(officewithNameAddr); //} //JavaScriptSerializer javaSerial = new JavaScriptSerializer(); //string officesJson = javaSerial.Serialize(officesWithNameAddress); //officesInMap = officesJson.Replace("\"Street\"", "street").Replace("\"City\"", "city").Replace("\"State\"", "state").Replace("\"PostalCode\"", "postalCode").Replace("\"Name\"", "name"); }