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!
insted of shareLockMapActivity use SherlockMapFragment
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.