title: Android Studio Google Maps Working on Android Device but not on Emulator
body: <p>I am trying to get my current location in Android Studio by using the Google Maps API Key I got from Google Cloud platform.
  If I run the app on my phone, everything is OK.
  If I run the app on the emulator, my location appears to be Google Plex, as in the following image(which would be completely wrong):
  <a href="https://i.stack.imgur.com/jdwZQ.png" rel="nofollow noreferrer">emulator app showing the wrong location</a></p>
  <p>I am not sure if it's because of the API key or maybe a mistake in the code/persmission/GPS?
  I took the code from a tutorial, but now it seems that Google Client is now deprecated (not sure if this is the problem).
  I believe it is because of the emulator, but I don't know why.I am currently using Pixel 2 API 26.</p>
  <p>I will show the code here:</p>
  <pre><code>  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;
  &lt;uses-permission android:name=&quot;com.google.android.providers.gsf.permisson.READ_GSERVICES&quot;/&gt;
  &lt;meta-data
          android:name=&quot;com.google.android.geo.API_KEY&quot;
          android:value=&quot;@string/google_maps_key&quot; /&gt;
  </code></pre>
  <p>BUILD.GRADLE:</p>
  <pre><code>implementation 'com.google.android.gms:play-services-maps:17.0.1'
  implementation 'com.google.android.gms:play-services-location:18.0.0'
  </code></pre>
  <p>MAPS ACTIVITY:</p>
  <pre><code>public class GoogleMapsActivity extends FragmentActivity implements OnMapReadyCallback,
      GoogleApiClient.ConnectionCallbacks,
      GoogleApiClient.OnConnectionFailedListener,
      LocationListener {
  
  private GoogleMap mMap;
  private GoogleApiClient googleClient;
  private LocationRequest locationRequest;
  private Location ultimateLocation;
  private Marker markerCurrentLocation;
  private static final int Request_User_Location_Code = 90;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_google_maps);
  
      if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M)
      {
          checkLocationPermission();
      }
  
      // Obtain the SupportMapFragment and get notified when the map is ready to be used.
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
              .findFragmentById(R.id.map);
      assert mapFragment != null;
      mapFragment.getMapAsync(this);
  
  }
  
  @Override
  public void onMapReady(@NotNull GoogleMap googleMap) {
      mMap = googleMap;
      //current location
      if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
          createGoogleApiClient();
          mMap.setMyLocationEnabled(true);
      }
  
  
  }
  
  protected synchronized void createGoogleApiClient() { // ok
      googleClient = new GoogleApiClient.Builder(this)
              .addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this)
              .addApi(LocationServices.API)
              .build();
      googleClient.connect();
  
  }
  
  @Override
  public void onLocationChanged(@NonNull Location location) { // ok
      ultimateLocation = location;
      if (markerCurrentLocation !=null)
      {
          markerCurrentLocation.remove();;
      }
      LatLng coordinates = new LatLng(location.getLatitude(), location.getLongitude());
      MarkerOptions markerOptions = new MarkerOptions();
      markerOptions.position(coordinates);
      markerOptions.title(&quot;Current Location&quot;);
      markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
  
      markerCurrentLocation = mMap.addMarker(markerOptions);
      mMap.moveCamera(CameraUpdateFactory.newLatLng(coordinates));
      mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 17.0f));
  
      if(googleClient!=null)
      {
          LocationServices.FusedLocationApi.removeLocationUpdates(googleClient,this);
      }
      else
      {
          Toast.makeText(this, &quot;NULLLLLLLL&quot;, Toast.LENGTH_SHORT).show();
      }
  
  }
  
  
  @Override
  public void onConnected(@Nullable Bundle bundle) { // ok
      locationRequest = new LocationRequest();
      locationRequest.setInterval(1100);
      locationRequest.setFastestInterval(1100);
      locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
  
      if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
          LocationServices.FusedLocationApi.requestLocationUpdates(googleClient, locationRequest, this);
      }
  }
  
  public boolean checkLocationPermission(){ // ok
      boolean ret;
      if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
          if(ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.ACCESS_FINE_LOCATION))
          {
              ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Request_User_Location_Code);
          }
          else
          {
              ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Request_User_Location_Code);
  
          }
          ret = false;
      }
      else
      {
          ret = true;
      }
      return ret;
  }
  //ok
  @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
      switch (requestCode)
      {
          case Request_User_Location_Code:
              if(grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED)
              {
                  if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED)
                  {
                      if(googleClient==null)
                      {
                          createGoogleApiClient();;
                      }
                      mMap.setMyLocationEnabled(true);
                  }
              }
              else
              {
                  Toast.makeText(this, &quot; PERMISSION DENIED&quot;, Toast.LENGTH_SHORT).show();
              }
              return ;
      }
  }
  
  @Override
  public void onConnectionSuspended(int i) {
  
  }
  
  @Override
  public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  
  }
  </code></pre>
  <p>}</p>