예제 #1
0
        /// <summary>
        /// 位置情報を取得ボタン クリックイベント
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async Task GetPositionButton_ClickedAsync(object sender, EventArgs e)
        {
            if (!IsLocationAvailable())
            {
                return;
            }

            var result = await GetCurrentPosition();

            var pItem = new Models.Position(result);

            editPosition.Text = pItem.ProcessingForDisplay();
            AddPosition(result);
        }
예제 #2
0
        // MAPの長押しイベント
        private void MyMap_MapLongClicked(object sender, MapLongClickedEventArgs e)
        {
            var pin = new Pin()
            {
                Type        = PinType.Place,
                Label       = "Long Tapped",
                Address     = "Added New Pin",
                Position    = e.Point,//長押しした地図上の位置
                Rotation    = 33.3f,
                Tag         = "",
                IsDraggable = true,
            };

            MyMap.Pins.Add(pin);

            var pItem = new Models.Position(pin);

            editPosition.Text = pItem.ProcessingForDisplay();
        }
예제 #3
0
        /// <summary>
        /// 現在のロケーションを取得
        /// </summary>
        /// <returns></returns>
        public static async Task <Plugin.Geolocator.Abstractions.Position> GetCurrentPosition()
        {
            Plugin.Geolocator.Abstractions.Position position = null;
            try
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;

                position = await locator.GetLastKnownLocationAsync();

                if (position != null)
                {
                    //got a cahched p, so let's use it.
                    return(position);
                }

                if (!locator.IsGeolocationAvailable || !locator.IsGeolocationEnabled)
                {
                    //not available or enabled
                    return(null);
                }

                position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to get location: " + ex);
            }

            if (position == null)
            {
                return(null);
            }

            var pItem = new Models.Position(position);

            Debug.WriteLine(pItem.ProcessingForDisplay());

            return(position);
        }