google maps integration and SlidingMenu(谷歌地图集成和滑动菜单)
问题描述
我想实现 Google maps v2 和 jfeinstein10 的 SliderMenu,我设法实现了 SliderMenu,但是当我想在活动中添加地图时,我得到了错误
I want to implement Google maps v2 and SliderMenu of jfeinstein10, I managed to implement the SliderMenu but when I want to add the map in the activity, I get error
GoogleMap 地图 = ((SupportMapFragment) getSupportFragmentManager (). FindFragmentById (R.id.fragMapa)).获取地图();
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager (). FindFragmentById (R.id.fragMapa)). GetMap ();
在 getSupportFragmentManager () 中更具体
being more specific in getSupportFragmentManager ()
任何集成两者的解决方案.我放了活动的代码.
any solution for that integrate both. I put the code of the activity.
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.google.android.gms.maps.CameraUpdate;
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.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;
public class ActivityPrincipal extends SlidingActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_principal);
GoogleMap mapa = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fragMapa)).getMap();
LatLng coordenadasGT = new LatLng(15.45368,-90.485115);
CameraPosition camPos = new CameraPosition.Builder()
.target(coordenadasGT)
.zoom(8)
.build();
CameraUpdate camUpd = CameraUpdateFactory.newCameraPosition(camPos);
mapa.moveCamera(camUpd);
}
/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_principal, menu);
return true;
}
*/
}
推荐答案
我成功集成了 Google maps v2 和 jfeinstein10 的 SliderMenu.我的 Activity 扩展了 ActionBarActivity 并且我通过以编程方式构建它来使用滑块菜单:
I managed to integrate Google maps v2 and SliderMenu of jfeinstein10. My Activity extends ActionBarActivity and i am using slider menu by constructing it programmatically :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT_OF);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.options);
menu.setShadowDrawable(R.drawable.shadow);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.setOnOpenedListener(this);
FragmentManager fmanager = getSupportFragmentManager();
Fragment fragment = fmanager.findFragmentById(R.id.mapView);
SupportMapFragment supportmapfragment = (SupportMapFragment) fragment;
mMap = supportmapfragment.getMap();
mMap.getUiSettings().setZoomControlsEnabled(false);
mMap.setOnMapClickListener(this);
mMap.setOnInfoWindowClickListener(this);
mMap.setOnMarkerClickListener(this);
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationChangeListener(this);
mMap.setOnMyLocationButtonClickListener(this);
}
mapView 是我布局中的一个片段:
mapView is a Fragment in my layout:
<fragment
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
这篇关于谷歌地图集成和滑动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:谷歌地图集成和滑动菜单
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01