Search This Blog

Sunday 25 December 2016

Button Click

Loction Button Click Event:-
-----------------------------
  string strLatitute = e.lat.ToString();
  string strLongitute = e.lng.ToString();
  var address = await DependencyService.Get<IReverseGeocode>().ReverseGeoCodeLatLonAsync(Convert.ToDouble(strLatitute), Convert.ToDouble(strLongitute));
  lblSummaryLoction.Text = address.Address1;



 if (App.isFifthPage)
            {
                btnMedicationNext.Text = "SUBMIT";
            }
            else {
                btnMedicationNext.Text = "NEXT";
            }

            btnMedicationNext.Clicked += delegate
            {
                if (App.isFifthPage)
                {
                    App.isFifthPage = false;
                    Navigation.PopModalAsync();

                }

Android ReverseGeocode Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Runtime.CompilerServices;
using Mig.Droid;
using Xamarin.Forms;
using Android.Locations;
using System.Threading.Tasks;

[assembly: Xamarin.Forms.Dependency(typeof(ReverseGeocode))]
namespace Mig.Droid
{
    public class ReverseGeocode : IReverseGeocode
    {
        public ReverseGeocode()
        {

        }
        public async Task<LocationAddress> ReverseGeoCodeLatLonAsync(double lat, double lon)
        {
            var geo = new Geocoder(Forms.Context);
            var addresses = await geo.GetFromLocationAsync(lat, lon, 1);
            if (addresses.Any())
            {
                var place = new LocationAddress();
                var add = addresses[0];
                place.Name = add.FeatureName;
                if (add.MaxAddressLineIndex > 0)
                {
                    place.Address1 = add.GetAddressLine(0);
                }
                place.City = add.Locality;
                place.Province = add.AdminArea;
                place.ZipCode = add.PostalCode;
                place.Country = add.CountryCode;
                return place;
            }

            return null;
        }
    }
}

LocationAddress Class in PCL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mig
{
   public class LocationAddress
    {
        public LocationAddress()
        {
        }
        public string Name { get; set; }
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string ZipCode { get; set; }
        public string Country { get; set; }
    }
}

IReverseGeocode Interface Class

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mig
{
   public interface IReverseGeocode
    {
        Task<LocationAddress> ReverseGeoCodeLatLonAsync(double lat, double lon);
    }
}

Full Address Url site

https://visualstudiomagazine.com/articles/2015/09/01/native-services-with-xamarinforms.aspx

Thursday 22 December 2016

Restrict

 int _Medicianlimit = 3;
            etMedicationName.TextChanged += (sender, args) =>
            {
                string _text = etMedicationName.Text;      //Get Current Text
                bool isDotValue = isDot(etMedicationName);

                if (_text.Length == 2)
                {
                    char[] chars = _text.ToCharArray();
                    if (chars[1]!='.')
                    {
                        _text = _text.Remove(_text.Length - 1);
                        etMedicationName.Text = _text;
                    }
                }
                else
                {
                    if (_text.Length > _Medicianlimit)       //If it is more than your character restriction
                    {
                        _text = _text.Remove(_text.Length - 1);  // Remove Last character
                        etMedicationName.Text = _text;        //Set the Old value
                    }
                }
            };

Wednesday 21 December 2016

naviga

App.Xaml.Cs:
After Partial Class

 public static bool isFifthPage = false;
-----------------------------------------

MEdication page Button Click:
   btnMedicationNext.Clicked += delegate
            {
                if (App.isFifthPage)
                {
                    App.isFifthPage = false;
                    Navigation.PopModalAsync();

                }
                else
                {

                    string strMedicationName = "";
                    foreach (var eachItem in objMEdicationWithDosage)
                    {
                 
-------------------------------------------------------------

Last Page Button Click:

 var startTap = new TapGestureRecognizer();
            startTap.Tapped += (s, e) =>
            {
                App.isFifthPage = true;
                Navigation.PushModalAsync(new MedicationPage());
            };     

Tuesday 20 December 2016

Address API

http://maps.googleapis.com/maps/api/geocode/json?latlng=18.589235,73.738853&sensor=true

https://maps.googleapis.com/maps/api/geocode/json?latlng=18.589235,73.738853&key=AIzaSyBkimSBhY8b1SQKeXWitEJ7ntCOVIl6uUw

Entery With Validation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace Mig
{
    public partial class NotePage : ContentPage
    {
        String strMessage = "";
        public NotePage()
        {
            Title = "Note";
            InitializeComponent();
            btnNoteRemindme.Clicked += delegate
            {
                Navigation.PushModalAsync(new SummaryPage());
            };
            btnNoteNext.Clicked += delegate
            {
                Navigation.PushModalAsync(new SummaryPage());
            };


            etNote.TextChanged += EtNote_TextChanged;

            var TapPaininAbdomen = new TapGestureRecognizer();
            TapPaininAbdomen.Tapped += (sender, e) =>
            {
                if (string.IsNullOrWhiteSpace(etNote.Text))
                {
                    etNote.Text = (etNote.Text + "Pain in the abdomen" + ", ");
                }
                else
                {
                    string strName = etNote.Text;
                    string strNewChar = strName.Substring(Math.Max(0, strName.Length - 2));

                    if (strNewChar == ", ")
                    {
                        if (etNote.Text.Length > 0)
                        {
                            etNote.Text = etNote.Text.Substring(0, etNote.Text.Length - 2);
                            bool isExisting = false;
                            string[] items = etNote.Text.ToString().Split(',');
                            foreach (var eachItem in items)
                            {
                                if (eachItem == "Pain in the abdomen")
                                {
                                    isExisting = true;
                                    break;
                                }
                            }
                            if (!isExisting)
                            {
                                etNote.Text = (etNote.Text + ", " + "Pain in the abdomen" + ", ");
                            }
                        }
                    }
                }
            };
            lblPainInTheAbdomen.GestureRecognizers.Add(TapPaininAbdomen);

            var TapLossOfPain = new TapGestureRecognizer();
            TapLossOfPain.Tapped += (sender, e) =>
            {
                if (string.IsNullOrWhiteSpace(etNote.Text))
                {
                    etNote.Text = (etNote.Text + "Loss of appetite" + ", ");
                }
                else
                {
                    if (etNote.Text.Length > 0)
                    {
                        string strName = etNote.Text;
                        string strNewChar = strName.Substring(Math.Max(0, strName.Length - 2));
                        if (strNewChar == ", ")
                        {
                            etNote.Text = etNote.Text.Substring(0, etNote.Text.Length - 2);
                            bool isExisting = false;
                            string[] items = etNote.Text.ToString().Split(',');
                            foreach (var eachItem in items)
                            {
                                if (eachItem == "Loss of appetite")
                                {
                                    isExisting = true;
                                    break;
                                }
                            }
                            if (!isExisting)
                            {
                                etNote.Text = (etNote.Text + ", " + "Loss of appetite" + ", ");
                            }
                        }
                    }
                }
            };
            lblLossOfPain.GestureRecognizers.Add(TapLossOfPain);

            var TapNauseaOfVomting = new TapGestureRecognizer();
            TapNauseaOfVomting.Tapped += (sender, e) =>
            {
                if (string.IsNullOrWhiteSpace(etNote.Text))
                {
                    etNote.Text = (etNote.Text + "Nausea or Vomiting" + ", ");
                }
                else
                {
                    string strName = etNote.Text;
                    string strNewChar = strName.Substring(Math.Max(0, strName.Length - 2));
                    if (strNewChar == ", ")
                    {
                        if (etNote.Text.Length > 0)
                        {
                            etNote.Text = etNote.Text.Substring(0, etNote.Text.Length - 2);
                            bool isExisting = false;
                            string[] items = etNote.Text.ToString().Split(',');
                            foreach (var eachItem in items)
                            {
                                if (eachItem == "Nausea or Vomiting")
                                {
                                    isExisting = true;
                                    break;
                                }
                            }
                            if (!isExisting)
                            {
                                etNote.Text = (etNote.Text + ", " + "Nausea or Vomiting" + ", ");
                            }
                        }
                    }
                }
            };
            lblNauseaOfVomting.GestureRecognizers.Add(TapNauseaOfVomting);
        }
           
        private void EtNote_TextChanged(object sender, TextChangedEventArgs e)
        {
            strMessage = e.NewTextValue;
        }
    }
}

Monday 12 December 2016

ad

  string strLatitute = e.lat.ToString();
            string strLongitute = e.lng.ToString();
            //string locationUrl = "http://api.openweathermap.org/data/2.5/weather?lat="+ strLatitute +"&lon="+ strLongitute + "&appid=b631adf3653df30af9ce66a72cf9b6de";



            string strNewsLocationUrl = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+strLatitute+","+strLongitute+"&key=AIzaSyBkimSBhY8b1SQKeXWitEJ7ntCOVIl6uUw";

            HttpClient objHttpClient = new HttpClient();
            var locationDetails =await objHttpClient.GetStringAsync(strNewsLocationUrl);
            var Locations = JsonConvert.DeserializeObject<AddressModel>(locationDetails.ToString());

Sunday 11 December 2016

Numarical

 int _Dosagelimit = 3;
            etDosage.TextChanged += (sender, args) =>
            {
                int n;
                var isNumeric = int.TryParse(etDosage.Text, out n);
                if (isNumeric)
                {
                    string _text = etDosage.Text;      //Get Current Text
                    if (_text.Length > _Dosagelimit)       //If it is more than your character restriction
                    {
                        _text = _text.Remove(_text.Length - 1);  // Remove Last character
                        etDosage.Text = _text;        //Set the Old value
                    }
                }
                else
                {
                    string _text = etDosage.Text;
                    if (_text.Length > 0)
                    {
                        _text = _text.Remove(_text.Length - 1);
                        etDosage.Text = _text;
                    }
                }
            };

Change

  var TapJustNow = new TapGestureRecognizer();
            TapJustNow.Tapped += TapJustNow_Tapped;
            slJustNow.GestureRecognizers.Add(TapJustNow);

            var Tap15MinAgo = new TapGestureRecognizer();
            Tap15MinAgo.Tapped += Tap15MinAgo_Tapped;
            sl15MintsAgo.GestureRecognizers.Add(Tap15MinAgo);

            var Tap30MinAgo = new TapGestureRecognizer();
            Tap30MinAgo.Tapped += Tap30MinAgo_Tapped;
            sl30Mints.GestureRecognizers.Add(Tap30MinAgo);

            var Tap1HourAgo = new TapGestureRecognizer();
            Tap1HourAgo.Tapped += Tap1HourAgo_Tapped;
            sl1HourAgo.GestureRecognizers.Add(Tap1HourAgo);

            var Tap2HourAgo = new TapGestureRecognizer();
            Tap2HourAgo.Tapped += Tap2HourAgo_Tapped;
            sl2HoursAgo.GestureRecognizers.Add(Tap2HourAgo);
        }
        private void TapJustNow_Tapped(object sender, EventArgs e)
        {
            imgchangeJustNow.Source = "med_select.png";
            imgchange15Minago.Source = "med_deselect.png";
            imgchange30Minago.Source = "med_deselect.png";
            imgchange1HourAgo.Source = "med_deselect.png";
            imgchange2HourAgo.Source = "med_deselect.png";
            DateTime oDate = Convert.ToDateTime(App.strDateTime);
            long milli = (long)(oDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
            var milliseconds = 0 * 60000;
            var diff = milli - milliseconds;
            string strNewTime = TimeUtility.getDate(diff.ToString());
            lblMainTime.Text = strNewTime;
        }
        private void Tap15MinAgo_Tapped(object sender, EventArgs e)
        {
            imgchange15Minago.Source = "med_select.png";
            imgchangeJustNow.Source = "med_deselect.png";
            imgchange30Minago.Source = "med_deselect.png";
            imgchange1HourAgo.Source = "med_deselect.png";
            imgchange2HourAgo.Source = "med_deselect.png";
            DateTime oDate = Convert.ToDateTime(App.strDateTime);
            long milli = (long)(oDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
            var milliseconds = 15 * 60000;
            var diff = milli - milliseconds;
            string strNewTime = TimeUtility.getDate(diff.ToString());
            lblMainTime.Text = strNewTime;
        }
        private void Tap30MinAgo_Tapped(object sender, EventArgs e)
        {
            imgchange30Minago.Source = "med_select.png";
            imgchangeJustNow.Source = "med_deselect.png";
            imgchange15Minago.Source = "med_deselect.png";
            imgchange1HourAgo.Source = "med_deselect.png";
            imgchange2HourAgo.Source = "med_deselect.png";
            DateTime oDate = Convert.ToDateTime(App.strDateTime);
            long milli = (long)(oDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
            var milliseconds = 30 * 60000;
            var diff = milli - milliseconds;
            string strNewTime = TimeUtility.getDate(diff.ToString());
            lblMainTime.Text = strNewTime;
        }
        private void Tap1HourAgo_Tapped(object sender, EventArgs e)
        {
            imgchange1HourAgo.Source = "med_select.png";
            imgchangeJustNow.Source = "med_deselect.png";
            imgchange15Minago.Source = "med_deselect.png";
            imgchange30Minago.Source = "med_deselect.png";
            imgchange2HourAgo.Source = "med_deselect.png";
            DateTime oDate = Convert.ToDateTime(App.strDateTime);
            long milli = (long)(oDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
            var milliseconds = 60 * 60000;
            var diff = milli - milliseconds;
            string strNewTime = TimeUtility.getDate(diff.ToString());
            lblMainTime.Text = strNewTime;
        }
        private void Tap2HourAgo_Tapped(object sender, EventArgs e)
        {
            imgchange2HourAgo.Source = "med_select.png";
            imgchangeJustNow.Source = "med_deselect.png";
            imgchange15Minago.Source = "med_deselect.png";
            imgchange30Minago.Source = "med_deselect.png";
            imgchange1HourAgo.Source = "med_deselect.png";
            DateTime oDate = Convert.ToDateTime(App.strDateTime);
            long milli = (long)(oDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
            var milliseconds = 120 * 60000;
            var diff = milli - milliseconds;
            string strNewTime = TimeUtility.getDate(diff.ToString());
            lblMainTime.Text = strNewTime;
        }

    }
}

Time

public class TimeUtility
    {
        public static string getCurrentDateTime(DateTime date)
        {
            DateTime dt = date;
            return dt.ToString("HH:mm tt  dd MMM yyyy");
        }

        public static string getDate(string startdatetime)
        {
            long microSec = Convert.ToInt64(startdatetime);
            DateTime converted = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddTicks(Convert.ToInt64(microSec) * 10000);
            return getCurrentDateTime(converted);
        }
    }
// App.strDateTime=TimeUtility.getCurrentDateTime(DateTime.Now);

Wednesday 7 December 2016

N

 public partial class MedicationPage : ContentPage
    {
        ObservableCollection<MedicationWithDosage> objMEdicationWithDosage = null;
        public MedicationPage()
        {
            Title = "Medication";
            InitializeComponent();

            btnSave.Clicked += BtnSave_Clicked;
            addMedicineDialogScroll.IsVisible = false;
            LoadMEdicationWithDosageData();
            btnMedicationRemindme.Clicked += delegate
            {
                Navigation.PushModalAsync(new NotePage());
            };
            btnMedicationNext.Clicked += delegate
            {
                string strMedicationName = "";
                foreach (var eachItem in objMEdicationWithDosage)
                {
                    if (eachItem.ImgPic == "med_select.png" && eachItem.MedicationName != "None")
                    {
                        strMedicationName = strMedicationName + eachItem.MedicationName + ",";
                    }
                }
                strMedicationName = strMedicationName.Substring(0, strMedicationName.Length - 1);
                strMedicationName = strMedicationName + ".";

             
                App.strMedicationName = strMedicationName;
                Navigation.PushModalAsync(new NotePage());
            };
            int _Medicianlimit = 30;
            etMedicationName.TextChanged += (sender, args) =>
            {
                string _text = etMedicationName.Text;      //Get Current Text
                if (_text.Length > _Medicianlimit)       //If it is more than your character restriction
                {
                    _text = _text.Remove(_text.Length - 1);  // Remove Last character
                    etMedicationName.Text = _text;        //Set the Old value
                }
            };
            int _Dosagelimit = 3;
            etDosage.TextChanged += (sender, args) =>
            {
                string _text = etDosage.Text;      //Get Current Text
                if (_text.Length > _Dosagelimit)       //If it is more than your character restriction
                {
                    _text = _text.Remove(_text.Length - 1);  // Remove Last character
                    etDosage.Text = _text;        //Set the Old value
                }
            };
        }
        private void BtnSave_Clicked(object sender, EventArgs e)
        {
            if(etMedicationName!=null && etMedicationName.Text.Trim().Length>0)
            {
                var selectedItems = (from p in objMEdicationWithDosage where p.MedicationName == etMedicationName.Text select p).ToList();
                if (selectedItems.Count > 0)
                {
                    DisplayAlert("error", "medicationName already you have added to List.", "ok");
                    return;
                }
                else
                {
                    objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = etMedicationName.Text, ImgPic = "med_deselect.png" });
                    lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;
                    etMedicationName.Text = "";
                    etDosage.Text = "";
                }
            }
            else
            {
                DisplayAlert("error", "Please Enter medicationName", "ok");
                return;
            }
        }
        public void Handle_Clicked(object sender, EventArgs e)
        {
            addMedicineDialogScroll.IsVisible = true;
        }

        public void OnSaveButtonClicked(object sender, EventArgs args)
        {
            addMedicineDialogScroll.IsVisible = false;
        }

        public void OnCancelButtonClicked(object sender, EventArgs args)
        {
            addMedicineDialogScroll.IsVisible = false;
        }
        public void LoadMEdicationWithDosageData()
        {
            objMEdicationWithDosage = new ObservableCollection<MedicationWithDosage>();
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "None", ImgPic = "med_select.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Zooming (600 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Calpol (650 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Figorty (230 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Higtyui (500 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Firtosia (300 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Glinica (300 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Migoi (300 mg)", ImgPic = "med_deselect.png" });
            lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;

            lstMedicationWithDosage.ItemSelected += LstMedicationWithDosage_ItemSelected;
        }

        private void LstMedicationWithDosage_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return; // ensures we ignore this handler when the selection is just being cleared
            }
            lstMedicationWithDosage.ItemsSource = null;
            MedicationWithDosage item = e.SelectedItem as MedicationWithDosage;
            if (item.ImgPic == "med_select.png")
            {
                item.ImgPic = "med_deselect.png";
            }
            else
            {
                item.ImgPic = "med_select.png";
            }
            var selectedItems = (from s in objMEdicationWithDosage where s.ImgPic == "med_select.png"
                                 && s.MedicationName!= "None" select s).ToList();
            if (selectedItems.Count > 0)
            {
                objMEdicationWithDosage[0].ImgPic = "med_deselect.png";
            }
            else
            {
                objMEdicationWithDosage[0].ImgPic = "med_select.png";
            }

            if (item.MedicationName == "None")
            {
                var selectedItemsList = (from s in objMEdicationWithDosage
                                         where s.ImgPic == "med_select.png" select s).ToList();
                foreach(var eachItem in selectedItemsList)
                {
                    eachItem.ImgPic = "med_deselect.png";
                }
                item.ImgPic ="med_select.png";
            }
            lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;
            ((ListView)sender).SelectedItem = null;
        }
    }

Tuesday 6 December 2016

ListView Examples


 private void LstMedicationWithDosage_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            lstMedicationWithDosage.ItemsSource = null;
            var item = e.SelectedItem as MedicationWithDosage;
            if (item.ImgPic == "med_select.png")
            {
                item.ImgPic = "med_deselect.png";
            }
            else
            {
                item.ImgPic = "med_select.png";
            }
            var selectedItems = (from s in objMEdicationWithDosage where s.ImgPic == "med_select.png"
                                 && s.MedicationName!= "None" select s).ToList();
            if (selectedItems.Count > 0)
            {
                objMEdicationWithDosage[0].ImgPic = "med_deselect.png";
            }
            else
            {
                objMEdicationWithDosage[0].ImgPic = "med_select.png";
            }
            lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;
        }
------------------------------

 btnMedicationNext.Clicked += delegate
            {
                string strMedicationName = "";
                foreach (var eachItem in objMEdicationWithDosage)
                {
                    if (eachItem.ImgPic == "med_select.png" && eachItem.MedicationName != "None")
                    {
                        strMedicationName = strMedicationName + eachItem.MedicationName + ",";
                    }
                }
                //strMedicationName = strMedicationName.Substring(0, strMedicationName.Length - 1);
                App.strMedicationName = strMedicationName;
                Navigation.PushModalAsync(new NotePage());
            };
---------------------------------
    var strtap = new TapGestureRecognizer();
            strtap.Tapped += Strtap_Tapped;
            sl30Mints.GestureRecognizers.Add(strtap);
        }
        private void Strtap_Tapped(object sender, EventArgs e)
        {
            DateTime oDate = Convert.ToDateTime(App.strDateTime);
            var ms = (oDate - DateTime.MinValue).TotalMilliseconds;
            var ss = ms;
        }

Sunday 4 December 2016

LoctonEventRising

  private void showtheLocationDetails()
        {
            DependencyService.Get<IMyLocation>().ObtainMyLocation();
            DependencyService.Get<IMyLocation>().locationObtained += MainPage_locationObtained;
        }

        private async void MainPage_locationObtained(object sender, ILocationEventArgs e)
        {
            string strLatitute = e.lat.ToString();
            string strLongitute = e.lng.ToString();
            string locationUrl = "http://api.openweathermap.org/data/2.5/weather?lat="+ strLatitute +"&lon="+ strLongitute + "&appid=b631adf3653df30af9ce66a72cf9b6de";
            HttpClient objHttpClient = new HttpClient();
            var locationDetails =await objHttpClient.GetStringAsync(locationUrl);
            var Locations = JsonConvert.DeserializeObject<LocationModel>(locationDetails.ToString());

            lblSummaryLoction.Text = Locations.name;
            lblSummaryWeather.Text = (Locations.weather[0].description) +",," +(Locations.main.temp) + ",,"+(Locations.main.humidity) + (Locations.main.pressure);
            var ss = Locations;
        }

GetMyLocation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Mig.Droid;
using Android.Locations;
using Xamarin.Forms;

[assembly: Xamarin.Forms.Dependency(typeof(GetMyLocation))]
namespace Mig.Droid
{
   public class GetMyLocation : Java.Lang.Object,
                                IMyLocation,
                                ILocationListener {
        LocationManager lm;
        public void OnProviderDisabled(string provider) { }
        public void OnProviderEnabled(string provider) { }
        public void OnStatusChanged(string provider,
            Availability status, Android.OS.Bundle extras)
        { }
        //---fired whenever there is a change in location---
        public void OnLocationChanged(Location location)
        {
            if (location != null)
            {
                LocationEventArgs args = new LocationEventArgs();
                args.lat = location.Latitude;
                args.lng = location.Longitude;
                locationObtained(this, args);
            };
        }
        //---an EventHandler delegate that is called when a location
        // is obtained---
        public event EventHandler<ILocationEventArgs> locationObtained;
        //---custom event accessor that is invoked when client
        // subscribes to the event---
        event EventHandler<ILocationEventArgs> IMyLocation.locationObtained
        {
            add
            {
                locationObtained += value;
            }
            remove
            {
                locationObtained -= value;
            }
        }
        //---method to call to start getting location---
        public void ObtainMyLocation()
        {
            lm = (LocationManager)Forms.Context.GetSystemService(Context.LocationService);
            lm.RequestLocationUpdates( LocationManager.NetworkProvider,
                    0,   //---time in ms---
                    0,   //---distance in metres---
                    this);
        }
        //---stop the location update when the object is set to
        // null---
        ~GetMyLocation()
        {
            lm.RemoveUpdates(this);
        }
}
  public class LocationEventArgs : EventArgs, ILocationEventArgs
    {
        public double lat { get; set; }
        public double lng { get; set; }
    }

}

LocationModel

namespace Mig.Model
{
   public class LocationModel
    {
        public Coord coord { get; set; }
        public List<Weather> weather { get; set; }

        public string newdata { get; set; }
        public Main main { get; set; }
        public Wind wind { get; set; }
        public Clouds clouds { get; set; }
        public int dt { get; set; }
        public Sys sys { get; set; }
        public int id { get; set; }
        public string name { get; set; }
        public int cod { get; set; }
    }


    public class Coord
    {
        public double lon { get; set; }
        public double lat { get; set; }
    }

    public class Weather
    {
        public int id { get; set; }
        public string main { get; set; }
        public string description { get; set; }
        public string icon { get; set; }
    }

    public class Main
    {
        public double temp { get; set; }
        public double pressure { get; set; }
        public int humidity { get; set; }
        public double temp_min { get; set; }
        public double temp_max { get; set; }
        public double sea_level { get; set; }
        public double grnd_level { get; set; }
    }

    public class Wind
    {
        public double speed { get; set; }
        public double deg { get; set; }
    }

    public class Clouds
    {
        public int all { get; set; }
    }

    public class Sys
    {
        public double message { get; set; }
        public string country { get; set; }
        public int sunrise { get; set; }
        public int sunset { get; set; }
    }
}

PCL Interface

namespace Mig
{
   public interface IMyLocation
    {
        void ObtainMyLocation();
        event EventHandler<ILocationEventArgs> locationObtained;
    }

    public interface ILocationEventArgs
    {
        double lat { get; set; }
        double lng { get; set; }
    }
}