Example #1
0
        private void GetStoreList(HttpContext context)
        {
            int    productId = 0;
            string text      = context.Request["fromLatLng"];

            if (string.IsNullOrEmpty(text))
            {
                context.Response.Write("无法定位");
            }
            else
            {
                text = text.Trim().Replace(" ", "");
                string[] array      = text.Split(',');
                string   fromLatLng = array[1] + "," + array[0];
                string   s          = context.Request["productId"];
                int.TryParse(s, out productId);
                IList <StoresInfo> nearbyStores  = StoresHelper.GetNearbyStores(fromLatLng, productId, "", true);
                StringBuilder      stringBuilder = new StringBuilder();
                if (nearbyStores.Count == 0)
                {
                    stringBuilder.Append("[]");
                }
                else
                {
                    stringBuilder.Append("[");
                    foreach (StoresInfo item in nearbyStores)
                    {
                        stringBuilder.Append("{");
                        stringBuilder.AppendFormat("\"StoreId\":\"{0}\",", item.StoreId);
                        stringBuilder.AppendFormat("\"StoreName\":\"{0}\",", item.StoreName);
                        stringBuilder.AppendFormat("\"Address\":\"{0}\",", item.Address);
                        stringBuilder.AppendFormat("\"Tel\":\"{0}\",", item.Tel);
                        stringBuilder.AppendFormat("\"Longitude\":\"{0}\",", item.Longitude);
                        stringBuilder.AppendFormat("\"Latitude\":\"{0}\",", item.Latitude);
                        stringBuilder.AppendFormat("\"Distance\":\"{0}\"", (item.Distance < 1000.0) ? (item.Distance.F2ToString("f2") + "米") : ((item.Distance / 1000.0).F2ToString("f2") + "KM"));
                        stringBuilder.Append("},");
                    }
                    stringBuilder.Remove(stringBuilder.Length - 1, 1);
                    stringBuilder.Append("]");
                }
                context.Response.ContentType = "text/json";
                context.Response.Write(stringBuilder.ToString());
            }
        }