SaharSafran February 2016

empty map when run code in android studio

I have a problem with the show map, But why show empty map ?! like in images

sample

I'll introduce you my code I put key in file release/res/values/google_map_api.xml and also put in debug/res/values/google_map_api.xml

<resources>
    <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
        AIzaSyDci-------------hSik
    </string>
</resources>

also I put my key in androidManifest.xml

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyDci-------------hSik" />

and the code of MapActivity.java

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

Note: Use Mobile Galaxy Note not emulator of android studio.

Answers


Nithinjith February 2016

Please check the permission part under manifest

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<permission
        android:name="com.example.map.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
<permission
          android:name="com.example.map.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>


Abhinaw Kumar February 2016

Add This in android manifest

   <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

Post Status

Asked in February 2016
Viewed 1,234 times
Voted 12
Answered 2 times

Search




Leave an answer