我试图显示 map ,但显示此错误,“为main类型未定义方法getSupportFragmentMananger()”。谢谢。我正在使用Google Maps AP
package com.maps;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
public class main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GoogleMap mMap;
mMap = ((MapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//can pass dynamic variables
final LatLng place = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(place)
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.fromResource(android.R.drawable.bottom_bar)));
}
}
最佳答案
public class main extends Activity
您应该使用
AppCompatActivity
或FragmentActivity
,例如public class mai extends AppCompatActivity
代替
public class main extends Activity
关于android - 方法getSupportFragmentManager()未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16396235/