I use Eclipse ,Android SDK and i have a class to do not put every code in main activity :
blablabla
import blablabla
..
..
public class Mhelper {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
Context mContext;
public Mhelper(Context ctx) {
this.mContext= ctx;
}
public void pinpointlocation(Context context){
map = ((SupportMapFragment) ((FragmentActivity) mContext).getSupportFragmentManager().findFragmentById(R.id.mapview))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
....
....
....
and i put a viewmap in xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
...
...
...
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="KEY"
/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/button2" />
</RelativeLayout>
And the program compile and install without any error but when i run app in emulator i get:
blablabla
04-23 11:36:32.408: E/AndroidRuntime(2515): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hach/com.example.hach.MainActivity}: android.view.InflateException: Binary XML file line #48: Error inflating class com.google.android.maps.MapView
blablabla
04-23 11:36:32.408: E/AndroidRuntime(2515): Caused by: android.view.InflateException: Binary XML file line #48: Error inflating class com.google.android.maps.MapView
blablabla
04-23 11:36:32.408: E/AndroidRuntime(2515): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity.
And i search in stack and find this ,this and this.
First one just confess he shouldn't use viewmap and second one told to read this refrence which is good one but i read it and can't find any solution which i can apply in my project.third one said Google Maps Android API v2 is good one.
And i found this link which is good example but i don't want to use tabs,should i? besides the line
import com.google.android.maps.MapActivity;
is the problem when i create new class and i want to extend MapActivity,the IDE don't know MapActivity.
Is there any thing that i can do to my current project without any complete change of app, to show the map and point a location as i code? should i extend MapActivity and add it to the project?Is there any simple solution like mapview?