2017-04-03 1 views
0

フラグメント内にGoogleマップを表示しようとしています。問題は、私がこの地図が表示されないプロジェクトを実行するときです。追加情報は、このフラグメントがPager Viewに属していることです。問題は、私は私のプロジェクトを実行したとき、私は、このマップが表示されないですGPSツールの作成方法は?

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 

     thisContext = inflater.getContext(); 
     View view = inflater.inflate(R.layout.tab_fragment_2, container, false); 
     loadMap(); 
     // initializeMap(); 

     locationManager = (LocationManager) thisContext.getSystemService(Context.LOCATION_SERVICE); 

     if (ActivityCompat.checkSelfPermission(thisContext, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(thisContext, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      // TODO: Consider calling 
      // ActivityCompat#requestPermissions 
      // here to request the missing permissions, and then overriding 
      // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
      //           int[] grantResults) 
      // to handle the case where the user grants the permission. See the documentation 
      // for ActivityCompat#requestPermissions for more details. 
      return null; 
     } 
     locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, this); 

     return view; 

    } 


    private void initializeMap() { 
     if (map == null) { 
      SupportMapFragment mapFrag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); 
      mapFrag.getMapAsync(this); 
     } 
    } 

    private void loadMap() { 
     SupportMapFragment mSupportMapFragment; 

     mSupportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); 
     if (mSupportMapFragment == null) { 
      FragmentManager fragmentManager = getFragmentManager(); 
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
      mSupportMapFragment = SupportMapFragment.newInstance(); 
      fragmentTransaction.replace(R.id.map, mSupportMapFragment).commit(); 
     } 

     if (mSupportMapFragment != null) { 
      mSupportMapFragment.getMapAsync(new OnMapReadyCallback() { 
       @Override 
       public void onMapReady(GoogleMap googleMap) { 
        if (googleMap != null) { 

         googleMap.getUiSettings().setAllGesturesEnabled(true); 

         // -> marker_latlng // MAKE THIS WHATEVER YOU WANT 

         //CameraPosition cameraPosition = new CameraPosition.Builder().target(marker_latlng).zoom(15.0f).build(); 
         // CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition); 
         // googleMap.moveCamera(cameraUpdate); 

        } 

       } 
      }); 
     } 
    } 

答えて

0

これはコードの私のサンプルです。

デフォルトの「新しいアクティビティ」ウィザードを使用して、Googleマップのアクティビティを作成できます。 必要なすべての情報が含まれています。次のスクリーンショットの7番目の項目を参照してください。

0

フラグメントのための私が知っている、これまで最もよい事はMapViewの代わりMapFragmentを使用することです。私はNavigation Drawerの断片の中でMapViewを使用しています。それはすべてcallbacksとなります。PlacesAutoCompleteです。

関連する問題