문제

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).

도움이 되었습니까?

해결책

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

다른 팁

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 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top