Question

The problem is that I added GoogleMap activity to my application and I even get the key but the map is showing only in the emulator. When I download my app on different devices the map is not working. All I can see is just an empty view but with "Google" string and with "+-" keys. I thought that loading is too long but I think that it can't be more than 10 minutes with wi-fi. Here is my code:

MapsActivity.java

public class MapsActivity extends ActionBarActivity {

private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private static final LatLng TRACKTOR = new LatLng(55.1747, 61.2871);


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


    LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabled = service
            .isProviderEnabled(LocationManager.GPS_PROVIDER);

   // check if enabled and if not send user to the GPS settings
   // Better solution would be to display a dialog and suggesting to
   // go to the settings
    if (!enabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }


    // Move the camera instantly to Sydney with a zoom of 15.
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(TRACKTOR, 15));

// Zoom in, animating the camera.
    mMap.animateCamera(CameraUpdateFactory.zoomIn());

// Zoom out to zoom level 10, animating with a duration of 2 seconds.
    mMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

// Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(TRACKTOR)      // Sets the center of the map to Mountain View
            .zoom(17)                   // Sets the zoom
            .bearing(90)                // Sets the orientation of the camera to east
            .tilt(30)                   // Sets the tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        Log.w("MAP","is showing now!");
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap();
        } else Log.w("MAP","is not showing!");
    }
}

/**
 * This is where we can add markers or lines, add listeners or move the camera. In this case, we
 * just add a marker near Africa.
 * <p>
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    mMap.addMarker(new MarkerOptions().position(new LatLng(55.1747, 61.2871)).title("Ледовая арена \"Трактор\""));
    mMap.setBuildingsEnabled(true);
  }
}

activity_maps.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.project1.2014.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Was it helpful?

Solution

It happens because u have used debug key which only works when deployed through ADT.

Your app needs release key to work on all mobiles.

you can check out here about release certificate

OTHER TIPS

Get the Google Maps API Key and add into the AndroidManifest.xml

<application>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyDSWlBiYKjYujZeJ_312345g0qXpxuaKZY" />
 </application>

Obtain Google Maps API Key

You probably installed the app by signing it with your debug key and using a debug maps key, or at least that is the issue with Version 1 Maps API. Not sure about Version 2. So try signing it as if you were going to release it on the Play Store and then install that on your phone and see if it works.

Also with Version 1 API you had to put the correct (production vs debug) key in your layout file that had the Maps object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top