Reputation: 161
I'm new on Stackoverflow. I have a problem with displaing a map on new Google Maps API v2. I done all the steps from this page https://developers.google.com/maps/documentation/android/start?hl=pl ans some tutorials and i can't display the map. When i run my application, on emulator displays only magnification controls and rest screen is white and i can't open it on my real device (HTC Wildfire S- android 2.3.5). I added google_play_service_lib into my project too. I was looking for answer for my problem on a lot of pages and in a lot of tutorials but i don't found it! Please help me!
It's my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adrianspora.googlemaptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.adrianspora.googlemaptest.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD6r1gse4Jx4sTrCECvLQQwgxLJikHm4Ow"/>
</application>
<permission
android:name="com.adrianspora.googlemaptest.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.adrianspora.googlemaptest.permission.MAPS_RECEIVE"/>
<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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
</manifest>
There's code of MainActivity:
package com.adrianspora.googlemaptest;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
}
And it's main layout's code:
<LinearLayout 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" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
There is a list of logs displays in LogCat :
06-22 14:51:44.897: D/AndroidRuntime(1092): Shutting down VM
06-22 14:51:44.927: W/dalvikvm(1092): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-22 14:51:44.996: E/AndroidRuntime(1092): FATAL EXCEPTION: main
06-22 14:51:44.996: E/AndroidRuntime(1092): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adrianspora.googlemaptest/com.adrianspora.googlemaptest.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.os.Looper.loop(Looper.java:137)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-22 14:51:44.996: E/AndroidRuntime(1092): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 14:51:44.996: E/AndroidRuntime(1092): at java.lang.reflect.Method.invoke(Method.java:511)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-22 14:51:44.996: E/AndroidRuntime(1092): at dalvik.system.NativeStart.main(Native Method)
06-22 14:51:44.996: E/AndroidRuntime(1092): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.Activity.setContentView(Activity.java:1881)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.adrianspora.googlemaptest.MainActivity.onCreate(MainActivity.java:15)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.Activity.performCreate(Activity.java:5104)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-22 14:51:44.996: E/AndroidRuntime(1092): ... 11 more
06-22 14:51:44.996: E/AndroidRuntime(1092): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
06-22 14:51:44.996: E/AndroidRuntime(1092): ... 21 more
06-22 15:00:25.848: D/dalvikvm(1273): GC_CONCURRENT freed 256K, 15% free 2600K/3032K, paused 85ms+37ms, total 193ms
06-22 15:00:26.236: D/dalvikvm(1273): GC_CONCURRENT freed 272K, 14% free 2742K/3188K, paused 72ms+5ms, total 116ms
06-22 15:00:26.267: E/Google Maps Android API(1273): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above
06-22 15:00:26.487: D/dalvikvm(1273): GC_FOR_ALLOC freed 152K, 11% free 2895K/3224K, paused 40ms, total 41ms
06-22 15:00:26.747: D/dalvikvm(1273): GC_CONCURRENT freed 85K, 8% free 3271K/3540K, paused 22ms+87ms, total 155ms
06-22 15:00:27.057: D/libEGL(1273): Emulator without GPU support detected. Fallback to software renderer.
06-22 15:00:27.087: I/Choreographer(1273): Skipped 56 frames! The application may be doing too much work on its main thread.
06-22 15:00:27.127: D/libEGL(1273): loaded /system/lib/egl/libGLES_android.so
06-22 15:00:27.188: D/gralloc_goldfish(1273): Emulator without GPU emulation detected.
06-22 15:00:28.117: D/dalvikvm(1273): GC_CONCURRENT freed 266K, 12% free 3470K/3912K, paused 36ms+7ms, total 128ms
06-22 15:00:28.117: D/dalvikvm(1273): WAIT_FOR_CONCURRENT_GC blocked 79ms
06-22 15:00:28.216: D/dalvikvm(1273): GC_FOR_ALLOC freed 435K, 18% free 3340K/4044K, paused 45ms, total 51ms
06-22 15:00:28.348: D/dalvikvm(1273): GC_CONCURRENT freed 326K, 15% free 3470K/4044K, paused 15ms+8ms, total 69ms
06-22 15:00:28.348: D/dalvikvm(1273): WAIT_FOR_CONCURRENT_GC blocked 45ms
06-22 15:00:28.557: D/dalvikvm(1273): GC_CONCURRENT freed 551K, 19% free 3399K/4152K, paused 21ms+26ms, total 113ms
06-22 15:00:36.126: E/Google Maps Android API(1273): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
06-22 15:00:36.136: E/Google Maps Android API(1273): Ensure that the following correspond to what is in the API Console: Package Name: com.adrianspora.googlemaptest, API Key: AIzaSyD6r1gse4Jx4sTrCECvLQQwgxLJikHm4Ow, Certificate Fingerprint: 1D915CBBCDEBB8CECC48371ED32EE0D5CA5DB443
06-22 15:14:09.636: E/Trace(1502): error opening trace file: No such file or directory (2)
06-22 15:14:11.196: D/dalvikvm(1502): GC_CONCURRENT freed 230K, 14% free 2599K/3004K, paused 124ms+91ms, total 328ms
06-22 15:14:11.386: E/Google Maps Android API(1502): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above
06-22 15:14:11.626: D/dalvikvm(1502): GC_CONCURRENT freed 264K, 14% free 2789K/3228K, paused 73ms+86ms, total 226ms
06-22 15:14:11.796: D/dalvikvm(1502): GC_FOR_ALLOC freed 119K, 12% free 2913K/3280K, paused 37ms, total 38ms
06-22 15:14:12.106: D/dalvikvm(1502): GC_CONCURRENT freed 64K, 8% free 3288K/3556K, paused 71ms+73ms, total 208ms
06-22 15:14:12.477: D/libEGL(1502): Emulator without GPU support detected. Fallback to software renderer.
06-22 15:14:12.496: D/libEGL(1502): loaded /system/lib/egl/libGLES_android.so
06-22 15:14:12.536: I/Choreographer(1502): Skipped 69 frames! The application may be doing too much work on its main thread.
06-22 15:14:12.656: D/gralloc_goldfish(1502): Emulator without GPU emulation detected.
06-22 15:14:13.307: D/dalvikvm(1502): GC_CONCURRENT freed 332K, 14% free 3358K/3868K, paused 143ms+137ms, total 477ms
06-22 15:14:13.307: D/dalvikvm(1502): WAIT_FOR_CONCURRENT_GC blocked 322ms
06-22 15:14:13.766: D/dalvikvm(1502): GC_CONCURRENT freed 365K, 15% free 3471K/4040K, paused 6ms+7ms, total 296ms
06-22 15:14:13.766: D/dalvikvm(1502): WAIT_FOR_CONCURRENT_GC blocked 97ms
06-22 15:14:13.866: D/dalvikvm(1502): GC_FOR_ALLOC freed 434K, 18% free 3342K/4040K, paused 39ms, total 46ms
06-22 15:14:14.056: D/dalvikvm(1502): GC_CONCURRENT freed 433K, 16% free 3400K/4040K, paused 12ms+27ms, total 109ms
06-22 15:14:18.076: E/Google Maps Android API(1502): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
06-22 15:14:18.076: E/Google Maps Android API(1502): Ensure that the following correspond to what is in the API Console: Package Name: com.adrianspora.googlemaptest, API Key: AIzaSyD6r1gse4Jx4sTrCECvLQQwgxLJikHm4Ow, Certificate Fingerprint: 1D915CBBCDEBB8CECC48371ED32EE0D5CA5DB443
06-22 15:14:23.066: I/Choreographer(1502): Skipped 96 frames! The application may be doing too much work on its main thread.
Upvotes: 1
Views: 10299
Reputation: 2363
I had the same error and tried like 6 tutorials, and read all the documentation from google. And finnally I've got it running and displaying the map. This is how it works for me.
1.Remove the libraries google-play-services and android support-v4 from both your eclipse and your PC. 2.Download again it from de sdk-manager. 3.Follow the instructions [here] (https://developers.google.com/maps/documentation/android/intro#sample_code) go to Sample Code and do as it says. Check specially this Existing Android Code Into Workspace , do not import the libraries as projects, they won't work. 4.Change all your MapFragment for SupportMapFragment, don't foget to extend your Actvity to FragmentActivity (that was my fail). 5.Disable (if it is enabled) the build automatically option from your project. 6.Clean the project. 5.Enable the build automatically option.
It should work.
Upvotes: 0
Reputation: 1154
You have to use FragmentActivity
public class PlacesMapActivity extends android.support.v4.app.FragmentActivity
implements OnClickListener, LocationListener {
ImageButton btn_home;
private GoogleMap mMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mMap = fragment.getMap();
mMap.setMyLocationEnabled(true);
// mMap = ((SupportMapFragment) getSupportFragmentManager()
// .findFragmentById(R.id.map)).getMap();
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.title("First Location");
markerOptions.snippet("This Is Test Location");
LatLng latlng = new LatLng(23.0333, 72.6167);
markerOptions.position(latlng);
// markerOptions.title("Ahmedabad Cordinat Found here");
// Marker m = mMap.addMarker(markerOptions);
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View myContentView = getLayoutInflater().inflate(
R.layout.custommarker, null);
TextView tvTitle = ((TextView) myContentView
.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
TextView tvSnippet = ((TextView) myContentView
.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());
return myContentView;
}
});
mMap.addMarker(new MarkerOptions()
.position(latlng)
.title("This is Sabarmati Ashram")
.snippet("Ahmedabad")
.icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(getBaseContext(),
DetailsOfPlacesActivity.class);
startActivity(intent);
}
});
btn_home = (ImageButton) findViewById(R.id.activity_map_ibtn_home);
btn_home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
Upvotes: 0
Reputation: 133560
You should use Support Fragment
since your min sdk is 8.
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Your activity must extend FragmentActivity
and to initialize GoogleMap object use the below.
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap();
Make sure you have added support library
Also make sure you imported the below
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
Check if you have enabled maps for android in google api console under services tab.
Check if you have followed all the steps mentioned in the docs
https://developers.google.com/maps/documentation/android/start
You can also check a similar question i answered.
App shows grid screen instead of google map
When i run my application, on emulator displays only magnification controls and rest screen is white
You should test it on a real device.
Upvotes: 4
Reputation: 33
What kind of API-key are you using? You should alway use a dev-key when programming and your app needs to be registered in the Google APIs Console.
And you have to add the google-play-services-library at Preferences/Android, NOT at Preferences/Java Build Path.
Upvotes: 0
Reputation: 190
You should use SupportMapFragment, since your API level is 2.3.5
Replace your fragment in the XML with:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
and also import this class in the Java file, instead of MapFragment.
Also, as a general advice, you should use the Support library if you want to support pre-Honeycomb devices and use fragments, etc.
Upvotes: 0