2016-08-22 15 views
0

私はAndroid Studio 1.1とAP1 21(コースの一部として必要なバージョン)を使用しています。私はGoogle Maps Activityを使って新しいプロジェクトを作成します。 setUpMapIfNeeded方法では、Error:(48, 21) error: cannot find symbol method getMap():自動的に生成されたコードの中でエラー:(48、21)エラー:シンボルメソッドが見つかりませんgetMap()

は、私は、次のエラーメッセージが表示されます

private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

任意のアイデアこの問題を解決する方法?ありがとう!

答えて

0

私は同じ方法を使用していましたが、同じエラーが発生しました。 OnMapReadyCallbackを実装して修正しました。

まずOnMapReadyCallback実装:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    ...... 
    .... 

新setUpMapIfNeeded()メソッド:

private void setUpMapIfNeeded() { 
    // Do a null check to confirm that we have not already instantiated the map. 
    if (mMap == null) { 
     // Try to obtain the map from the SupportMapFragment. 
     SupportMapFragment mf = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
     mf.getMapAsync(this); 
    } 
} 

と(setUpMapを呼び出す)オーバーライドonMapReady中:

@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 
    setUpMap(); 
} 

をsetUpMapに変更はありません()メソッドまたは他のメソッド。私はそれが助けて欲しい

関連する問題