【发布时间】:2017-06-15 00:56:19
【问题描述】:
我在尝试调用它时收到错误“无法解析符号 getMapAsync”。我读过其他帖子,但他们的代码也和我的一样。所以这里是:
package barsoftware.suedtirolpointer;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class Karte extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap m_map;
boolean mapReady = false;
MarkerOptions Rieserfernerhütte;
MarkerOptions Dahoam;
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
static final CameraPosition SÜDTIROL = CameraPosition.builder()
.target(new LatLng(46.470576, 11.339986))
.zoom(8)
.build();
@Override
public Resources getResources() {
return super.getResources();
}
////////////////////////////// LAYOUT //////////////////////////////
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from activity_main.xml
setContentView(R.layout.karte);
//// UP BOOTON ////
// Get a support ActionBar corresponding to this toolbar
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);
//////////////////////////////////////////////
//////////////// KARTEN POI'S ////////////////
//////////////////////////////////////////////
Rieserfernerhütte = new MarkerOptions()
.position(new LatLng(46.5324, 12.0446))
.title("Rieserfernerhütte");
Dahoam = new MarkerOptions()
.position(new LatLng(46.738886, 12.166471))
.title("Dahoam");
}
@Override
public void onMapReady(GoogleMap map) {
this.m_map = map;
mapReady = true;
m_map = map;
m_map.addMarker(Rieserfernerhütte);
m_map.addMarker(Dahoam);
flyTo(SÜDTIROL);
}
private void flyTo(CameraPosition target){
m_map.moveCamera(CameraUpdateFactory.newCameraPosition(target));
}
////////////////////////////////// MENU //////////////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_no_karte, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.menu_home) {
Intent Home = new Intent(Karte.this,
Start.class);
startActivity(Home);
}
if (id == R.id.menu_karte) {
}
if (id == R.id.menu_teilnehmer) {
Intent Teilnehmer = new Intent(Karte.this,
Teilnehmer.class);
startActivity(Teilnehmer);
}
if (id == R.id.menu_einstellungen) {
Intent Einstellungen = new Intent(Karte.this,
Einstellungen.class);
startActivity(Einstellungen);
}
if (id == R.id.menu_update) {
Intent Update = new Intent(Karte.this,
Update.class);
startActivity(Update);
}
if (id == R.id.menu_teilen) {
Intent Teilen = new Intent(Karte.this,
Teilen.class);
startActivity(Teilen);
}
return super.onOptionsItemSelected(item);
}
}
如果有人可以回答或知道是什么问题,请。
【问题讨论】:
标签: java android google-maps android-fragments