使用SupportMapFragment我可以获取一个地图来显示并加载到视图中。然而,这就是它所做的一切。我无法让它加载点,缩放或任何有价值的东西。
这里有什么问题?
我正在使用以下片段来启动SupportMapFragment。
public class MapLocationFragment extends Fragment {
public static MapLocationFragment getInstance()
{
return new MapLocationFragment();
}
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.view_map_location_fragment, null, false);
map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
return v;
}
}
我的活动如下所示:
public class MapLocationActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_map_location);
// handle beer venue list
MapLocationFragment fragment = MapLocationFragment.getInstance();
getSupportFragmentManager().beginTransaction()
.replace(R.id.venueMapSection, fragment)
.commit();
}
}