我试图在google map
上使用Android App
并且我遇到了一些问题,
首先是我的班级Geoloc.java
:
public class Geoloc extends MapFragment {
private MapView map;
private GoogleMap nmap;
private static final String TAG = "MyActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
Log.e(TAG, "super1");
Log.d(TAG, "super2");
Log.v(TAG, "super3");
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map, container, false);
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext()) == ConnectionResult.SUCCESS) {
map = (MapView) view.findViewById(R.id.mapView);
map.onCreate(savedInstanceState);
nmap = map.getMap();
nmap.getUiSettings().setMyLocationButtonEnabled(false);
nmap.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
nmap.addMarker(new MarkerOptions().position(new LatLng(10, 10)).title("Hello world"));
nmap.addMarker(new MarkerOptions().title("title").snippet("description").position(new LatLng(49.5594950, -1.8414880))).showInfoWindow();
} else {
Toast.makeText(getActivity(), "Please install google play services", Toast.LENGTH_LONG).show();
}
return view;
}
然后是我的Accueil.java
:
map.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
cancelAsyncTask();
fg = com.lan.me.Geoloc.newInstance();
//Geoloc = new Geoloc();
getFragmentManager().beginTransaction().replace(R.id.fg_accueil, fg).commit();
currentFg = CurrentFragment.MAP;
}
});
最后我的map.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.SupportMapFragment
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
我只是检查了一些log.d-e
,最后我才明白我的班级Geoloc
从未使用过,但我真的不明白为什么......?
有人知道如何解决这个问题吗? (我有一个map
但我无能为力,因为它只是创建它的xml
答案 0 :(得分:0)
我只是找到了怎么做,在我geoloc.java
我最终改变了很多事情:
public Geoloc() {
super();
}
public static Geoloc newInstance() {
Geoloc fragment = new Geoloc();
return fragment;
}
@Override
public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
View v = super.onCreateView(arg0, arg1, arg2);
initMap();
return v;
}
像这样,它运作正常!谢谢你的帮助。如果您愿意,可以关闭主题。