2017-04-03 1 views
0

Ich versuche Google Maps in meinem Fragment anzuzeigen. Das Problem ist, wenn ich mein Projekt starte, sehe ich diese Karten nicht. Die zusätzliche Information ist, dass Fragmente zu Pager View gehören.Wie erstellen Sie GPS-Tools?

Dies ist mein Beispielcode:

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); 

        } 

       } 
      }); 
     } 
    } 

Antwort

0

Das Problem ist, wenn ich mein Projekt betreibe ich diese Karten nicht sehen.

Sie können den Standardassistenten für neue Aktivitäten verwenden, um Google Maps-Aktivitäten zu erstellen. Es enthält alle Informationen, die Sie benötigen. Siehe den siebten Punkt im folgenden Screenshot.

0

Das Beste, was ich bisher für Fragment wissen ist MapView statt MapFragment zu verwenden. Ich benutze MapView in einem Navigation Drawer Fragment und es funktioniert gut mit allen callbacks, die ich brauche und PlacesAutoComplete.

Verwandte Themen