Android 如何创建GPS工具?

Android 如何创建GPS工具?,android,google-maps,gps,Android,Google Maps,Gps,我尝试在片段中显示谷歌地图。问题是,当我运行我的项目时,我看不到这些地图。附加信息是,此片段属于寻呼机视图 这是我的代码示例: public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { thisContext = inflater.getContext(); View view =

我尝试在片段中显示谷歌地图。问题是,当我运行我的项目时,我看不到这些地图。附加信息是,此片段属于寻呼机视图

这是我的代码示例:

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

                    }

                }
            });
        }
    }
问题是,当我运行我的项目时,我看不到这些地图

您可以使用默认的“新建活动”向导创建谷歌地图活动。 它包括您需要的所有信息。请参见以下屏幕截图中的第7项


到目前为止,我所知道的关于Fragment最好的方法是使用
MapView
而不是
MapFragment
。我在
导航抽屉中使用
MapView
片段,它可以很好地处理我需要的所有
回调和
placesautomplete