Witam. Mam problem z Google Maps. Otwieram aktywność z Google Maps z main activity ale pojawia się tylko zoom bez siatki i markera. Prosze o pomoc. Wygląda na to, że aplikacja jest overloaded.
Klasa odpowiedzialna za wyswietlanie mapy
package pl.kk.um;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
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.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps_activity);
setUpMapIfNeeded();
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(52.2568188797841, 22.5635361671448), 16));
}
@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();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
//mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(51.2568188797841, 22.5635361671448)));
}
}
main activity
Button button;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
button = (Button)findViewById(R.id.button);
button2 = (Button)findViewById(R.id.button2);
button.setOnClickListener(this);
button2.setOnClickListener(this);
}
private void MapsClick()
{
//Intent intent = new Intent(this, MapsActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//startActivity(intent);
startActivity(new Intent("android.intent.action.MapsActivity"));
}
public void onClick(View v)
{
switch (v.getId())
{
case R.id.button:
BuildingsMapButtonClick();
break;
case R.id.button2:
//AboutClick();
MapsClick();
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.kk.um" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BuildingsMap"
android:label="@string/title_activity_buildings_map"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="pl.kk.um.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.BuildingsMap" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".About"
android:label="@string/title_activity_about"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="pl.kk.um.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.About" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MapsActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
Android Studio logcat
GC_CONCURRENT freed 853K, 27% free 9192K/12576K, paused 4ms+12ms, total 85ms
10-24 19:04:54.837 20013-20313/pl.kk.um D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 66ms
[...]
GC_FOR_ALLOC freed 1658K, 26% free 9339K/12576K, paused 42ms, total 43ms
*Może powinno być pl.kk.um.android.permission.INTERNET?