title: Current Location Using Xamarin Android
body: <p>The problem is i'm trying to get the current location of the user and the code is not giving any error except that when the code compiles, it should execute onLocationChanged method but it does't executes it. 
  I have also Set the permissions right in my manifest file, but i don't know why i can't seem to understand what the problem is. Please help. </p>
  
  <h1><strong>Map Activity</strong></h1>
  
  <p>this is my map activity where i'm trying to set the marker to current location</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Text; 
  using Android.App;
  using Android.Content;
  using Android.Content.PM;
  using Android.Gms.Maps;
  using Android.Gms.Maps.Model;
  using Android.Graphics;
  using Android.Locations;
  using Android.OS;
  using Android.Runtime;
  using Android.Views;
  using Android.Widget;
  using Newtonsoft.Json;
  
  namespace RoutineApp
  {
      [Activity(Label = "GoogleMapDirectionsActivity", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, Theme = "@style/Theme.AppCompat.Light.NoActionBar")]
      public class GoogleMapDirectionsActivity : Activity, IOnMapReadyCallback, ILocationListener
      {
          private GoogleMap gMap;
          private MapFragment mapFragment;
          private LocationManager locationManager;
          string locationProvider;
          private MarkerOptions markerOptions;
          private Marker marker;
  
          protected override void OnCreate(Bundle savedInstanceState)
          {
              base.OnCreate(savedInstanceState);
              SetContentView(Resource.Layout.googlemapdirections);
  
              mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.DirectionMap);
              mapFragment.GetMapAsync(this);
              goBtn = FindViewById&lt;Button&gt;(Resource.Id.GoBtn);
  
              //user location
              IntializeLocationManager();
          }
          private void IntializeLocationManager()
          {
              locationManager = (LocationManager)GetSystemService(LocationService);
              Criteria criteriaForLocationService = new Criteria
              {
                  Accuracy = Accuracy.Fine
              };
              IList&lt;string&gt; acceptableLocationProviders = locationManager.GetProviders(criteriaForLocationService, true);
              if (acceptableLocationProviders.Any())
              {
                  locationProvider = acceptableLocationProviders.First();
              }
              else
              {
                  locationProvider = string.Empty;
              }
              //Log.Debug(TAG, "Using " + locationProvider + ".");
          }
          public void OnMapReady(GoogleMap googleMap)
          {
              gMap = googleMap;
              //mDirectionMap.TrafficEnabled = true;
              gMap.UiSettings.CompassEnabled = true;
              gMap.UiSettings.MyLocationButtonEnabled = true;
              gMap.UiSettings.ZoomControlsEnabled = true;
    OnLocationChanged(locationManager.GetLastKnownLocation(locationProvider));
          }
          protected override void OnResume()
          {
              base.OnResume();
              locationManager.RequestLocationUpdates(locationProvider, 400, 0, this);
          }
          protected override void OnPause()
          {
              base.OnPause();
              locationManager.RemoveUpdates(this);
          }
          public void OnLocationChanged(Location location)
          {
  
              if (marker != null)
              {
                  marker.Remove();
              }
              LatLng latLng = new LatLng(location.Latitude, location.Longitude);
              markerOptions = new MarkerOptions()
                  .SetPosition(latLng)
                  .SetTitle("My Current Position");
              marker = gMap.AddMarker(markerOptions);
              CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latLng, 19);
              gMap.MoveCamera(camera);
  
          }
  
          public void OnProviderDisabled(string provider)
          {
              //throw new NotImplementedException();
          }
  
          public void OnProviderEnabled(string provider)
          {
              //throw new NotImplementedException();
          }
  
          public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
          {
              //throw new NotImplementedException();
          }
  }
  </code></pre>
  
  <h1><strong>Xml Map activity</strong></h1>
  
  <p>xml for my map activity</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:weightSum="100"
      android:background="@android:color/holo_blue_dark"&gt;
      &lt;EditText
          android:id="@+id/SourceTxtBox"
          android:inputType="text"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_gravity="center_horizontal"
          android:background="@drawable/edit_text_style"
          android:layout_marginTop="10dp"
          android:layout_marginLeft="20dp"
          android:layout_marginRight="20dp"
          android:layout_marginBottom="10dp"
          android:hint="Enter Starting Point"
          android:layout_weight="7"
          android:textColorHint="#a3a3a3"
          android:textColor="#000" /&gt;
      &lt;EditText
          android:id="@+id/DestinationTxtBox"
          android:inputType="text"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_gravity="center_horizontal"
          android:background="@drawable/edit_text_style"
          android:layout_marginLeft="20dp"
          android:layout_marginRight="20dp"
          android:layout_marginBottom="10dp"
          android:hint="Enter Destination"
          android:layout_weight="7"
          android:textColorHint="#a3a3a3"
          android:textColor="#000" /&gt;
      &lt;fragment
          android:id="@+id/DirectionMap"
          android:layout_height="0dp"
          android:layout_width="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"
          android:layout_weight="80" /&gt;
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="6"
          android:weightSum="10"&gt;
          &lt;Button
              android:id="@+id/GoBtn"
              android:text="Go"
              android:textSize="10dp"
              android:textStyle="bold"
              android:layout_height="wrap_content"
              android:layout_width="20dp"
              android:layout_weight="1" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h1><strong>Manifest file</strong></h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.company.RoutineApp" android:versionCode="1" android:versionName="1"&gt;
    &lt;uses-sdk android:minSdkVersion="15" /&gt;
    &lt;!-- Google Maps for Android v2 requires OpenGL ES v2 --&gt;
    &lt;uses-feature android:glEsVersion="0x00020000" android:required="true" /&gt;
  
    &lt;!-- We need to be able to download map tiles and access Google Play Services--&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
    &lt;!-- Allow the application to access Google web-based services. --&gt;
    &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  
    &lt;!-- Google Maps for Android v2 will cache map tiles on external storage --&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
    &lt;!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data --&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
    &lt;!-- Permission to receive remote notifications from Google Play Services --&gt;
    &lt;!-- Notice here that we have the package name of our application as a prefix on the permissions. --&gt;
    &lt;uses-permission android:name="com.company.RoutineApp.permission.MAPS_RECEIVE" /&gt;
    &lt;permission android:name="com.company.RoutineApp.permission.MAPS_RECEIVE" android:protectionLevel="signature" /&gt;
  
        &lt;!-- These are optional, but recommended. They will allow Maps to use the My Location provider. --&gt;
        &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
        &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
        &lt;!--&lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;  
        &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;--&gt; 
    &lt;application android:label="@string/app_name" android:icon="@drawable/Icon" android:theme="@style/Theme.MyTheme"&gt;
      &lt;meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAGQlTIquLL5yyIr47pI_AA9g1CI-Whh0o" /&gt;
      &lt;meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /&gt;
    &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <h1><strong>This is the screen shot of my application</strong></h1>
  
  <p><a href="https://i.stack.imgur.com/BjhuM.png" rel="nofollow noreferrer" title="This is not my current location please help"><img src="https://i.stack.imgur.com/BjhuM.png" alt="enter image description here" title="This is not my current location please help"></a></p>