In this app, I am trying to add a functional V2 google map. I\'ve looked at most of the tutorials for creating an activity, obtaining a key for the maps, and creating the xm
Step 1: Include below line in manifest make sure you add within the application tag
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA0YQoByyHKGbB2R3pSIerQCEiGlwieRas" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Ex::
<application
android:name="taxialways.user.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="taxialways.user.Register"
android:label="@string/title_activity_register"
android:noHistory="true"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA0YQoByyHKGbB2R3pSIerQCEiGlwieRas" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Step 2: Make sure your activity extends FragmentActivity
Step 3: Use the mapFragment element as below in the xml
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@+id/lineartab" />
This problem happened to me and nothing seems to be wrong with my code ,after investigation I have noticed that the problem occurs when opening the activity after an instance run is applied during development so I just ignored it since instant run is never going to happen when the app is in the hands of a real user.!
I am trying to deploy Google Play Services V2 (for Google Map functionalities) on Android 2.3.4. (API level 10), I had the same problem. Here is how I solved it:
google-play-services_lib had to be included as a library. In Eclipse, you can do this as follows:
This is important: please ensure the project build target for the library is the same as the one used for your app.
Because the API version is beneath 11, SupportMapFragment is used instead of MapFragment.
Hope this helps. It has taken me at least three solid hours to work this one out.
Try out below code:
public class ShowActivity extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
setUpMapIfNeeded();
}
@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();
}
}
}
}
XML file code:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Manifest file code:
<permission
android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"/>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="removed" />
</application>
Add the following lines in your manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />