コード例 #1
0
        public static BusTrackingModel GetRealtimeBusLatLong(int student_id, int s_route_id)
        {
            BusTrackingModel list = new BusTrackingModel();

            try
            {
                var request = HttpWebRequest.Create(string.Format(BaseUrl + "get_realtime_location?student_id=" + student_id + "&route_id=" + s_route_id));
                request.ContentType = "application/json";
                request.Method      = "GET";
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
                    }
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        var     content = reader.ReadToEnd();
                        string  Parsing = content.ToString();
                        JObject jObj    = JObject.Parse(content);
                        var     item    = jObj["route_lat_lng"];
                        //var json = JsonValue.Parse(Parsing);
                        //var item = json["route_lat_lng"];

                        list.track_date = Convert.ToString(item[0]["track_date"].ToString());
                        list.route_id   = Convert.ToInt32(item[0]["route_id"].ToString());
                        list.driver_id  = Convert.ToInt32(item[0]["driver_id"].ToString());
                        list.lng        = Convert.ToDouble(item[0]["lng"].ToString());
                        list.track_id   = Convert.ToInt32(item[0]["track_id"].ToString());
                        list.lat        = Convert.ToDouble(item[0]["lat"].ToString());
                    }
                }
                return(list);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(list);
            }
        }
コード例 #2
0
        private void GetRealTimeLatLong()
        {
            model1 = new BusTrackingModel();
            try
            {
                //BTProgressHUD.Show();
                Task.Factory.StartNew(
                    // tasks allow you to use the lambda syntax to pass wor
                    () =>
                {
                    model1 = WebService.GetRealtimeBusLatLong(StaticDataModel.StudentId, StaticDataModel.StudentRouteId);
                }
                    ///
                    ).ContinueWith(
                    t =>
                {
                    if (model1 != null)
                    {
                        InvokeOnMainThread(() =>
                        {
                            if (mapview != null)
                            {
                                var annotation = mapview.Annotations;

                                for (int i = 0; i < annotation.Length; i++)
                                {
                                    var title = annotation[i].GetTitle();
                                    if (title == "studentname")
                                    {
                                        mapview.RemoveAnnotation(annotation[i]);
                                    }
                                }
                                ;
                            }
                            CLLocationCoordinate2D coordsforBus = new CLLocationCoordinate2D(model1.lat, model1.lng);
                            //MKCoordinateSpan span3 = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coordsforBus.Latitude));
                            //mapview.Region = new MKCoordinateRegion(coordsforBus, span3);
// get current region
                            MKCoordinateRegion region = mapview.Region;
// Update the center

                            region.Center = new CLLocationCoordinate2D(model1.lat, model1.lng);
// apply the new region
                            mapview.Region = region;

                            mapview.AddAnnotation(new CustomAnnotation(5, "studentname", coordsforBus));
                            mapview.ZoomEnabled = true;
                        });
                    }
                    else
                    {
                    }
                    //BTProgressHUD.Dismiss();
                }, TaskScheduler.FromCurrentSynchronizationContext()
                    );
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }