Using SupportMapFragment

The post "A simple example using Google Maps Android API v2" using com.google.android.gms.maps.MapFragment. It work on device run API 12 and above. For older API level, using com.google.android.gms.maps.SupportMapFragment.

SupportMapFragment on Nexus One running Android 2.3.6


Modify layout to replace com.google.android.gms.maps.MapFragment with com.google.android.gms.maps.SupportMapFragment.
<RelativeLayout 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"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout>


Modify main code to extend android.support.v4.app.FragmentActivity, rather than Activity. Otherwise, AndroidRuntime will be Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader.
package com.example.androidmapsv2;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

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

}



The series:
A simple example using Google Maps Android API v2, step by step.

thumbnail
Title: Using SupportMapFragment
Rating: 100% based on 99998 ratings. 10 user reviews.
Post by

Related articles :

0 comments:

Post a Comment

My Blog List

 
Copyright © 2015. About - Web Version - Mobile Version Sitemap - Contact - Privacy