Android google maps + sliding menu, implementation

Mardoqueu S.

I am beginner in programming and I've tried to implement the google maps inside sliding menu, at home, this is the fragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.moictab.decanias.MapActivity$PlaceholderFragment" >

<fragment 

          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"

          />

</RelativeLayout>

This is the class I want to put the maps

public class HomeFragment extends Fragment {

    public HomeFragment(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        android.app.FragmentTransaction mTransaction = getFragmentManager().beginTransaction();
        SupportMapFragment mFRaFragment = new MapFragment();
        Bundle args = new Bundle();
        args.putDouble("lat", -4.573362);
        args.putDouble("lng", -44.6020426);
        mFRaFragment.setArguments(args);
        mTransaction.add(R.id.map, mFRaFragment);
        mTransaction.commit();


        MapsInitializer.initialize(getApplicationContext());


        return rootView;
    }

}

But I am getting these errors

mTransaction.add(R.id.map, mFRaFragment);

The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, SupportMapFragment)

MapsInitializer.initialize(getApplicationContext());

The method getApplicationContext() is undefined for the type HomeFragment

The solution would be:

public class HomeFragment extends FragmentActivity {

And everything stay okay in this class, but in MainActivity is not acceptable because there is extends Fragment, I already tried to change there to FragmentActivity, but the the replace doesn't work:

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

message: "The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, FragmentActivity)"

I already tried to use android.support.v4.app.Fragment, but it doesn't work too. My problem is to implement the google maps android in navigation Drawer.

/**
 * Diplaying fragment view for selected nav drawer list item
 * */
private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new FindPeopleFragment();
        break;
    case 2:
        fragment = new PhotosFragment();
        break;
    case 3:
        fragment = new CommunityFragment();
        break;
    case 4:
        fragment = new PagesFragment();
        break;
    case 5:
        fragment = new WhatsHotFragment();
        break;

    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}

I have seen too many ways to do, but they don't work, like this as well:

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

and also import

import android.support.v4.app.FragmentActivity; Before you do this Right click project->properties->buildpath->java build path -> libraries .. then click on add external jars

the go to

\android-sdks\extras\android\support\v4

and select android-support-v4.jar
Emil Adz

As been stated by the error you receive:

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4452000 but found 0. You must have the following declaration within the element:

<meta-data 
android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" />

So you need to add this meta-data element to you Manifest file under the application hive:

<meta-data 
android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android Google Maps LocationClient

来自分类Dev

Android Google Maps图标

来自分类Dev

Android-Google Maps

来自分类Dev

Android Google Maps按钮样式

来自分类Dev

Android Google Maps经/纬度

来自分类Dev

Android Google Maps:getLastLocation与requestLocationUpdates

来自分类Dev

Android Google Maps移动相机

来自分类Dev

Android Google Maps SnapshotReadyCallback错误

来自分类Dev

Google Maps for Android签名过程

来自分类Dev

Android Google Maps按钮样式

来自分类Dev

Android SDK Eclipse Google Maps

来自分类Dev

内插Google Maps Android道路

来自分类Dev

Google Maps for android无法呈现

来自分类Dev

Android Google Maps,多个意图

来自分类Dev

Android:Google Maps Android API:授权失败

来自分类Dev

How to Integrate Google Maps in Android App

来自分类Dev

在Google Maps Android中动态更新标记

来自分类Dev

Android google maps cant zoom with compass active

来自分类Dev

Android Google Maps在片段内包含标记

来自分类Dev

Google Maps Android API v2

来自分类Dev

Google Android Maps v2 MetersToEquatorPixel

来自分类Dev

在Android Google Maps上检测拖动

来自分类Dev

在Android的Fragment中使用Google Maps

来自分类Dev

在Google Maps Android顶部显示按钮

来自分类Dev

Android Google Maps异步任务添加标记

来自分类Dev

Android中的Google Maps缩放错误

来自分类Dev

Android Google Maps APK显示灰色方块

来自分类Dev

Android Google Maps +滑动菜单,实现

来自分类Dev

Android Google Maps未显示绘制的圆圈