1

Hi i am trying to use the support map fragment to display a google map fragment and so far no joy dispite my project having both the android-support-v4 jar and the google-play-service_lib jar

here is my layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

my map activity

package com.jr.haliotest;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.jr.haliotest.utils.IntentFilters;
import com.jr.haliotest.utils.Position;

/**
 * @author RichardsJ
 * 
 */
public class MapActivity extends FragmentActivity  implements IntentFilters {

    private GoogleMap googleMap;

    private Position mPosition;

    private CameraPosition mCameraPosition;

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_view_layout); //fails here
        mPosition = getIntent().getParcelableExtra(INTENT_EXTRA_POSITION);
        mCameraPosition = new CameraPosition(new LatLng(
                mPosition.getLattitude(), mPosition.getLongetude()), 0, 0, 0);
        initialiseView();
    }

    private void initialiseView() {

        googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

        if (googleMap == null) {
            Log.d("", "Map wasnt loaded properly");
        } else {
            Log.d("", "Map loaded fine");
            googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        }

        googleMap.moveCamera(CameraUpdateFactory
                .newCameraPosition(mCameraPosition));

    }
}

full stack trace

  03-29 00:20:17.501: E/AndroidRuntime(2211): FATAL EXCEPTION: main
03-29 00:20:17.501: E/AndroidRuntime(2211): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
03-29 00:20:17.501: E/AndroidRuntime(2211):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.Activity.setContentView(Activity.java:1912)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at com.jr.haliotest.MapActivity.onCreate(MapActivity.java:36)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.Activity.performCreate(Activity.java:5066)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.ActivityThread.access$600(ActivityThread.java:151)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.os.Looper.loop(Looper.java:155)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at android.app.ActivityThread.main(ActivityThread.java:5485)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at java.lang.reflect.Method.invoke(Method.java:511)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
03-29 00:20:17.501: E/AndroidRuntime(2211):     at dalvik.system.NativeStart.main(Native Method)

it works fine if i use MapFragment objects instead of the supported objects.

any ideas? what am i missing? tried cleaning, closing eclipse, reinstalling app, no joy

Jono
  • 17,341
  • 48
  • 135
  • 217
  • refer this [link][1], it could be helpful [1]: http://stackoverflow.com/questions/13733299/initialize-mapfragment-programmatically-with-maps-api-v2 – VINIL SATRASALA Mar 29 '13 at 07:06

2 Answers2

5

I managed to get it to work.

here are concrete steps on how to use supported libs with google map v2.

  1. copy google play service lib into your lib folder
  2. copy android supported v4 lib in your lib folder
  3. Add 1 and 2 to your build path
  4. import google play service project into your workspace
  5. select your project and rigght click>properties>android>add project lib(the google play service) and do not tick "is library"
  6. Select the google play service project and right click and go to properties>android>tick "is lib"
  7. Use FragmentActivity and use Support to use supported libs.
  8. do clean and rebuild, exit eclipse, uninstall app previously on your device, load eclipse and do another clean and rebuild. It should now all work
Jono
  • 17,341
  • 48
  • 135
  • 217
0

You need to get the Google Play SDK:

http://developer.android.com/google/play-services/index.html

Basically, you may have the code in your extras directory, so you import it into your workspace, then compile it, add it to your project as a library and you should be set.

James Black
  • 41,583
  • 10
  • 86
  • 166
  • Thats exactly what i did already. i have the google-play-service.jar on my libs folder – Jono Mar 29 '13 at 00:40
  • i added the actual project folder as a dependency for my project and now it saying it cannot run the Android library – Jono Mar 29 '13 at 00:53
  • Are you trying to run the google play project? Otherwise you may want to go into detail with what you are doing. If I right-click on my project and do "run as ..." it finds the library but runs my project. – James Black Mar 29 '13 at 01:22