1

I want to implement google maps api v2 because my debug key from google maps v1 doesn't work if I want to publish on Google Play Store and I can be able to get a maps V1 release key because is deprecated.

Anybody know how to implement maps api v2 in SherlockMapActivity?

Thank you in advance!

jcamacho
  • 818
  • 2
  • 12
  • 25
  • we want some more explanation... what you are tying to do?? – Dhaval Parmar Jun 20 '13 at 08:55
  • possible duplicate of [Using ActionBarSherlock With the New SupportMapFragment](http://stackoverflow.com/questions/13721929/using-actionbarsherlock-with-the-new-supportmapfragment) – QED Nov 11 '13 at 20:39

3 Answers3

3

You cant. As per documentation, Google map v1 key no longer been maintained and moreover Sherlock map jar also been deprecated. https://github.com/JakeWharton/ActionBarSherlock-Plugin-Maps

Switch over to Google map v2 and use release key when you sign your apk and debug key for unsigned apk.

Shadow
  • 6,864
  • 6
  • 44
  • 93
  • What is deprecated?, SherlockMapActivity with google maps 2 or I can't use google maps 2 with some ABS activity. My app is based on ABS, how I use google maps 2 Map in my application in order to show the user's current location on google Map? – jcamacho Jun 20 '13 at 08:53
2

insted of shareLockMapActivity use SherlockMapFragment

create package name: com.actionbarsherlock.app inside of your Project not in sharelock lib.

add below class in to that package.

package com.actionbarsherlock.app;

import android.app.Activity;
import android.support.v4.app.Watson.OnCreateOptionsMenuListener;
import android.support.v4.app.Watson.OnOptionsItemSelectedListener;
import android.support.v4.app.Watson.OnPrepareOptionsMenuListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.internal.view.menu.MenuItemWrapper;
import com.actionbarsherlock.internal.view.menu.MenuWrapper;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.google.android.gms.maps.SupportMapFragment;

public class SherlockMapFragment extends SupportMapFragment implements
        OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener,
        OnOptionsItemSelectedListener {
    private SherlockFragmentActivity mActivity;

    public SherlockFragmentActivity getSherlockActivity() {
        return mActivity;
    }

    @Override
    public void onAttach(Activity activity) {
        if (!(activity instanceof SherlockFragmentActivity)) {
            throw new IllegalStateException(getClass().getSimpleName()
                    + " must be attached to a SherlockFragmentActivity.");
        }
        mActivity = (SherlockFragmentActivity) activity;

        super.onAttach(activity);
    }

    @Override
    public void onDetach() {
        mActivity = null;
        super.onDetach();
    }

    @Override
    public final void onCreateOptionsMenu(android.view.Menu menu,
            android.view.MenuInflater inflater) {
        onCreateOptionsMenu(new MenuWrapper(menu),
                mActivity.getSupportMenuInflater());
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // Nothing to see here.
    }

    @Override
    public final void onPrepareOptionsMenu(android.view.Menu menu) {
        onPrepareOptionsMenu(new MenuWrapper(menu));
    }

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        // Nothing to see here.
    }

    @Override
    public final boolean onOptionsItemSelected(android.view.MenuItem item) {
        return onOptionsItemSelected(new MenuItemWrapper(item));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Nothing to see here.
        return false;
    }
}

how use above class:

public class MyMapFragment extends SherlockMapFragment {

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (getMap() != null) {
            Log.e(getClass().getSimpleName(), "Map ready for use!");
            CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(
                    23.0333, 72.6167));
            CameraUpdate zoom = CameraUpdateFactory.zoomTo(10);

            getMap().moveCamera(center);
            getMap().animateCamera(zoom);

            addMarker(getMap(), Double.parseDouble(latlong[0]),
                        Double.parseDouble(latlong[1]), name, "" + sni);



        }

    }

    private void addMarker(GoogleMap map, double lat, double lon,
            String string, String string2) {
        map.addMarker(new MarkerOptions()
                .position(new LatLng(lat, lon))
                .title(string)
                .snippet(string2)
                .icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    }
}

add above fragment in any Activity like below

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <fragment class="com.dj_android.MyMapFragment"
            android:id="@+id/titles"
            android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>

Edited:

Please learn what is fragment.

how use fragment in Activity.

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
  • I just add the code, but, when I want to start activity I found the error "Unable to instantiate activity. I use this code to start activity Intent intent = new Intent(this, MyMapFragment.class); startActivity(intent); when startActivity called the app crashed. – jcamacho Jun 20 '13 at 10:47
  • @Camacho: we can't add fragment using intent. i have edited my answer please check both link. – Dhaval Parmar Jun 20 '13 at 11:24
0

deprecated means that they are no longer supported. Google has rolled out Google Maps V2 this year, april month, if not mistaken. From now all the new apps that need google maps must use google maps v2. Although apps using V1 key will continue to work. But new apps must use v2. check google site Google Maps V2 . Also if you want a beginners tutorial on Google Maps v2 then see this youtube tutorial youtube link.

Press check mark if this solved your question or mark it useful if it helped you in anyway.

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • I know "deprecated" but I don't understand if google maps v2 was unable to use with ABS... I see that is wrong, the problem is how to!. I tried to implement the code from Dhawal Sodha, I hope I can do that. I have a debug key for maps V1 but until two days ago I couldn't have a version to publish in google play, I never get a release key for V1 :( – jcamacho Jun 20 '13 at 10:51
  • Since you never got a release key for V1 so now u will never get a key for V1. Try to implement the code of Dhawal Sodha using the new V2 key. This is the only way left otherwise you won't be able to release this app. – Rohan Kandwal Jun 21 '13 at 08:28