Map version 2 in Android 2.3
Asked Answered
C

2

1

I have developed simple Map application using google map version2. It is working fine on Android 4.0 supported devices but not run in Android 2.3(API 10). Now I need to support the same application from API level 10. How to convert the application support from API level 10?

My application is supported the "google-play-services_lib".

my code sample.

main.xml:

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

java code:

    public class MainActivity extends Activity implements LocationListener{
        private GoogleMap mMap;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
           ........
       }
}

please help me to support from API 10(Android 2.3).

Canvas answered 1/8, 2013 at 11:16 Comment(2)
If it is working fine on 4.0 please confirm your 2.3 device installed google play services.Outman
use SupportMapFragment which is distributed as a part of support library for backward compatibilityBluegill
C
4

You mention API 10

You should use SupportMapFragment instead of MapFragment.

<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"  
android:layout_width="match_parent"
android:layout_height="match_parent"/>

You activity must also extend FragmentActivity.

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
mMap = fm.getMap(); 

Import

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment; 

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

Check the line above the topic Developer's guide

Conduction answered 1/8, 2013 at 11:19 Comment(1)
Thanks, it works, you saved my time. Is lower version can support all the features what support in 4.0s?Canvas
F
1

change to

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

and

extends FragmentActivity

and

mMap =((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();mMap 
Fehr answered 1/8, 2013 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.