我在下面发布了代码片段,因为我找不到命令setUpMapIfNeeded();
。当我输入必要的命令时,到处都是红线。任何人都可以帮我解决这个代码吗?另外,我的模拟器中没有任何标记。
我愿意接受建议,请帮助我。我用的min sdk版本是17,android studio版本是2.1。我正在使用 Googlemaps 活动。我仍然不明白为什么我没有得到setUpMapIfNeeded
命令以及内置代码片段的其余部分。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
同样在尝试丢失的代码后,我无法获得任何标记。然而,无论我在哪里在线搜索,我都会得到这个教程。
如果您知道任何其他代码,请告诉我。