Пример #1
0
        async protected override void OnAppearing()
        {
            base.OnAppearing();

            var locator  = CrossGeolocator.Current;
            var position = await locator.GetPositionAsync();

            Latitude  = position.Latitude;
            Longitude = position.Longitude;
            string GetAddress = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + Latitude.ToString() + "," + Longitude + "&key=" + api_key + "&language=th";

            DetailMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(Latitude, Longitude),
                                                               Distance.FromKilometers(1)));

            using (HttpResponseMessage response = await _client.GetAsync(GetAddress))
            {
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    using (HttpContent contents = response.Content)
                    {
                        string mycontent = await contents.ReadAsStringAsync();

                        JObject maps_details = JObject.Parse(mycontent);
                        location_details = maps_details["results"][0]["formatted_address"].ToString();
                    }
                }
                else
                {
                    await DisplayAlert("Error", "เกิดข้อผิดพลาดกรุณาลองใหม่", "OK");
                }
            }

            var pin = new Pin
            {
                Position = new Position(Latitude, Longitude),
                Label    = "ที่อยู่ปัจจุบัน",
                Address  = location_details
            };

            lb_Location_detail.Text = location_details;
            DetailMap.Pins.Add(pin);
        }
Пример #2
0
        public StationDetailPage(StationDetailViewModel model)
        {
            InitializeComponent();
            BindingContext = viewModel = model;

            // Set map frame to the location of the selected station
            var position = new Position(Convert.ToDouble(viewModel.Latitude),
                                        Convert.ToDouble(viewModel.Longitude));

            DetailMap.IsShowingUser = true;
            DetailMap.MoveToRegion(
                MapSpan
                .FromCenterAndRadius(position, Distance.FromMeters(500)));


            var pin = new Pin
            {
                Label    = viewModel.Name,
                Position = position,
                Type     = PinType.Place
            };

            DetailMap.Pins.Add(pin);
        }
Пример #3
0
        async protected override void OnAppearing()
        {
            animationView.IsVisible = true;
            base.OnAppearing();
            var locator  = CrossGeolocator.Current;
            var position = await locator.GetPositionAsync();

            var Latitude  = position.Latitude;
            var Longitude = position.Longitude;

            string GetAddress   = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + Latitude.ToString() + "," + Longitude + "&key=" + api_key + "&language=th";
            string sContentType = "application/json";
            var    jsonData     = "{\"work_id\":\"" + work_id + "\"}";
            var    content      = new StringContent(jsonData.ToString(), Encoding.UTF8, sContentType);

            using (HttpResponseMessage response = await _client.PostAsync(Url, content))
            {
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    using (HttpContent contents = response.Content)
                    {
                        string mycontent = await contents.ReadAsStringAsync();

                        List <Work_Detail> work_list = JsonConvert.DeserializeObject <List <Work_Detail> >(mycontent);

                        var latlong = "";

                        for (var j = 0; j < work_list.Count; j++)
                        {
                            latlong += work_list[j].lat + "," + work_list[j].@long + "|";
                        }

                        string GetAddress2 = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + Latitude + "," + Longitude + "&destinations=" + latlong + "&mode=driving&language=th-TH&sensor=false&key=AIzaSyA_v0m54p_3BHjOdaeteyY3VfvqoURhJ8Q&language=th";
                        using (HttpResponseMessage response2 = await _client.GetAsync(GetAddress2))
                        {
                            if (response2.StatusCode == System.Net.HttpStatusCode.OK)
                            {
                                using (HttpContent contents2 = response2.Content)
                                {
                                    string mycontent2 = await contents2.ReadAsStringAsync();

                                    JObject maps_details = JObject.Parse(mycontent2);
                                    var     map_d        = maps_details["rows"][0]["elements"][0]["distance"]["text"].ToString();
                                    var     map_r1       = map_d.Replace("กม.", "กิโลเมตร");
                                    var     map_r2       = map_r1.Replace("ม.", "เมตร");
                                    foreach (var x in work_list)
                                    {
                                        lb_owner_name.Text    = x.job_owner_name.ToString();
                                        lb_owner_tel.Text     = x.tel + "";
                                        lb_work_name.Text     = x.work_name.ToString();
                                        lb_work_desc.Text     = x.work_desc.ToString();
                                        lb_work_duration.Text = x.duration.ToString();
                                        lb_labor_cost.Text    = x.labor_cost.ToString() + " บาท";
                                        lb_loc.Text           = x.loc_name.ToString();
                                        lb_distance.Text      = map_r2;

                                        DetailMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(x.lat, x.@long),
                                                                                           Distance.FromKilometers(1)));
                                        var pin = new Pin
                                        {
                                            Position = new Position(x.lat, x.@long),
                                            Label    = "สถานที่ทำงาน",
                                            Address  = x.loc_name
                                        };



                                        DetailMap.Pins.Add(pin);

                                        DetailLoad.IsVisible    = true;
                                        animationView.IsVisible = false;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    await DisplayAlert("เกิดข้อผิดพลาด", "Member id is null", "ตกลง");
                }
            }
        }