2016-08-18 5 views
1

私はアンドロイド開発で新しく、アプリケーションを開発しましたが、今はアクティビティをフラグメントに変換しようとしています。私は断片化する既存のコードを変更する方法を理解していない私はフラグメントに変換するマップフラグメントアクティビティを持っています

Maps.java:

package com.ambisave; 

    import android.Manifest; 
    import android.content.pm.PackageManager; 
    import android.os.Bundle; 
    import android.support.v4.app.Fragment; 
    import android.view.LayoutInflater; 
    import android.view.View; 
    import android.view.ViewGroup; 
    import android.widget.RelativeLayout; 

    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.SupportMapFragment; 
    import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
    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 Maps extends Fragment implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    public void onMapReady(GoogleMap map) { 
    map.setMapType(GoogleMap.MAP_TYPE_NORMAL); 

    CameraPosition googlePlex = CameraPosition.builder() 
      .target(new LatLng(37.4219999, -122.0862462)) 
      .zoom(16) 
      .bearing(0) 
      .tilt(45) 
      .build(); 

    map.moveCamera(CameraUpdateFactory.newCameraPosition(googlePlex)); 
    map.addMarker(new MarkerOptions() 
      .position(new LatLng(17.440466, 78.496668)) 
      .title("SVIT") 
      .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher))); 


    if (checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     return; 
    } 
    map.setMyLocationEnabled(true); 


    } 

    private int checkSelfPermission(Maps maps, String accessCoarseLocation) { 


    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    View view = inflater.inflate(R.layout.fragment_maps, null); 

    setContentView(R.layout.fragment_maps); 
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
    GoogleMap mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap(); 
    } 
    } 

fragment_maps.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.ambisave.Maps"> 

    <!-- TODO: Update blank fragment layout --> 
    <fragment 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</RelativeLayout> 

これらは私が構築しようとした際、私は取得していますエラーです私を助けてください。

Error:(80, 101) error: cannot find symbol method getMap() 
:app:compileDebugJavaWithJavac FAILED 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

答えて

1

置き換える

MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); with 


MapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); 
関連する問題