【发布时间】:2013-08-30 12:09:21
【问题描述】:
我正在使用谷歌地图开发一个安卓应用程序。目前我可以在我的应用程序中查看地图,但我不知道如何在应用程序上查看当前位置。
这是我的代码:
public class MapsFragment extends Fragment{
MapView m;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View v = inflater.inflate(R.layout.map_near_me, container, false);
m = (MapView) v.findViewById(R.id.map);
m.onCreate(savedInstanceState);
return v;
}
}
已编辑: 和xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map" />
</LinearLayout>
这段代码工作正常,我知道'setmylocationenabled'可以帮助在FragmentActivity中启用,但不幸的是我必须使用类型作为'Fragment'。我正在使用谷歌 api v2。请有人帮忙。
【问题讨论】:
-
我们需要你的谷歌地图代码!!你从哪里得到地图来管理它?你应该使用 SupportMapFragment,使用 support lib v4 !!
-
@Yume117:检查我的xml代码出错了
-
使用 SupportMapFragment 或 Fragment Map 代替 MapView :)
-
所以你使用 Google map api v1 吗?因为不再推荐这种显示地图的方法:/
-
那么我如何在类类型片段中实现它?
标签: android google-maps android-layout android-mapview google-maps-android-api-2