Houssem
Houssem

Reputation: 2069

Maps api v2 android My location not working on 2.3.3

I'm using maps api v2 in android app that supports 2.3.3, and I set setMyLocationEnabled(true), of course I have my button which works fine on jelly bean, but not working on 2.3.3.

here are how I called the map :

    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();
        }
    }
}

private void setUpMap(){
    mMap.setMyLocationEnabled(true);
    if(ttdBranch!=null){
        mMap.addMarker(new MarkerOptions()
        .position(new LatLng(ttdBranch.getLatitude(), ttdBranch.getLongitude()))
        .snippet(getResources().getString(R.string.branch) + "\n" + ttdBranch.getName()));
        LatLng pos = new LatLng(ttdBranch.getLatitude(),ttdBranch.getLongitude());
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(pos, 14));
    }
}

here's manifest :

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

<permission android:name="*******.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>

<uses-permission android:name="*******.permission.MAPS_RECEIVE"/>
<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.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_ttd_petales"
    android:label="@string/app_name"
    android:theme="@style/Holo.Theme.Light" >
    <activity
        android:name="*******.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>

    <activity android:name="*******.BranchesMapActivity" />
    <activity android:name="*******.BranchDetailActivity"/>


    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="*******"/>

I maked sure that location sensor is enabled on the phone, and it's workin on Google Map app, but not in my app.

Any help ?

Thanks.

Upvotes: 4

Views: 2432

Answers (1)

BBonDoo
BBonDoo

Reputation: 766

Please check this below..

1.check if the "libs" folder containing the "android-support-v4.jar" exists in your project.

"android-support-v4.jar" is located in "/extras/android/compatibility/v4/android-support-v4.jar" under your "android-sdk" drectory.

"The Google Maps Android API requires API level 12 or higher for the support of MapFragment objects. If you are targeting an application earlier than API level 12, you can access the same functionality through the SupportMapFragment class. You will also have to include the Android Support Library." is described in this Android Development Guide(click here).

2.Before running your project, you must set your project Build target to "Google APIs", not Android x.x. version :

Select your project and click Project > Properties > Project Build Target in Eclipse and select any "Google APIs ", and then run your project on your real phone(handset). If you use the emulator, you will get the failed result because the app with the Google Play Service library is not supported in the emulator.

"Google Play services is not supported on the Android emulator — to develop using the APIs, you need to provide a development device such as an Android phone or tablet." is described in in this Android Development Guide(click here).

3.Once more, you don't need to create the new Google Maps API key in order to test your project, Just use the default provided API key, which is shown as "Key for browser apps (with referers) "in your Google APIs Console.

4.Finally, the most important is to add Google Play services as an Android library project as follows:

Select File > Import > Android > Existing Android Code Into Workspace and click Next. Select Browse..., enter /extras/google/google_play_services/libproject/google-play-services_lib, and click Finish.

I hope my comment will be useful to you.

Upvotes: 1

Related Questions