如何在SherlockMapActivity中实现google maps api v2

时间:2013-06-20 08:31:48

标签: android google-maps actionbarsherlock-map

我想实施google maps api v2,因为如果我想在Google Play商店发布我的调试密钥,那么我可以获得地图V1发布密钥,因为我已弃用。

有人知道如何在SherlockMapActivity中实现maps api v2吗?

提前谢谢!

3 个答案:

答案 0 :(得分:3)

你不能。根据文档,不再维护Google地图v1密钥,而且Sherlock地图jar也已被弃用。 https://github.com/JakeWharton/ActionBarSherlock-Plugin-Maps

切换到Google地图v2,并在为apk和调试密钥签署未签名的apk时使用发布密钥。

答案 1 :(得分:2)

insck of ShareLockMapActivity使用SherlockMapFragment

在项目内部创建包名称:com.actionbarsherlock.app而不是在sharelock lib。

将以下类添加到该包中。

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

如何使用上课:

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

在以下任何活动中添加以上片段

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

<强>编辑:

请了解what is fragment

how use fragment in Activity.

答案 2 :(得分:0)

已弃用表示不再支持。谷歌今年4月推出谷歌地图V2,如果没有记错的话。从现在起,所有需要谷歌地图的新应用都必须使用谷歌地图v2。虽然使用V1键的应用程序将继续工作。但新应用必须使用v2。检查谷歌网站Google Maps V2。此外,如果您想要Google Maps v2上的初学者教程,请参阅此YouTube教程youtube link

如果这解决了您的问题,请按复选标记,或者如果它对您有帮助则标记为有用。