Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps showing on emulator, but not on a device

I wrote a basic map application, the one that an be easily instantiated with AndroidStudio. The only difference the fragment is loaded inside another custom layout.

package com.wayl.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import com.wayl.R;

public class MapsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        FragmentManager myFragmentManager = getSupportFragmentManager();
        SupportMapFragment mapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);
        GoogleMap mMap = mapFragment.getMap();

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-35, 152);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker near Sidney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
[...]

As said above, the app works perfectly in the AVD, but no way to make it work on a real device. It shows just an empty map placeholder, and also the colourful Google logo is there. But no markers, no grid, no buttons, nothing else.

Why I think it should work:

  • Network, wifi, are ok, both on the phone as in the AVD

  • The OpenGL version shouldn't be a problem, I'm running the apk both on a Galaxy Samsung S3, and on a Galaxy Note 4.

  • I placed my fingerprints both for debug and release version retrieved with keytool and connected with my keystore, so key it's OK, you can also see the reference image, even if it said this is optional. I put both the base package and the package containing the Maps activity just for being sure.

  • I waited enough time for the app to fetch the location, and for the fingerprint to propagate in case this would be needed.

  • Manifest has all the correct permission to retrieve coarse and fine location (remember in the AVD everything works perfectly)

I already succeed in the past to develop a map on Android. I remember each time after 4 or 5 trial and errors on the frustrating process I could achieve it. This time I don't know what to do more. I'm exploting S.O. to understand where I am mistaking.

like image 641
Sandor Mezil Avatar asked Jan 07 '23 00:01

Sandor Mezil


1 Answers

I finally came to a solution.

In the new AndroidStudio sample, the file with the key (google_maps_api.xml) has been placed to the folder app\src\debug\res\values, and another one in app\src\release\res\values!

While AndroidStudio show you all layouts, all values files, and so on, there is just one value file with the key, so I couldn't notice there were actually two files in the file system, one with the key not setup! I didn't even now there could be different folder for that.

I struggled few days on this. It happens every time I try to create a simple maps, something is changed, pop ups and make me lose time. When you catch the solution everything seems so obvious, but in the meanwhile it's really frustrating.

Thank you to everybody helped! I really appreciated.

like image 196
Sandor Mezil Avatar answered Jan 11 '23 03:01

Sandor Mezil