Search in sources :

Example 1 with LocationManager

use of com.omkarmoghe.pokemap.controllers.map.LocationManager in project Pokemap by omkarmoghe.

the class MapWrapperFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    locationManager = LocationManager.getInstance(getContext());
    nianticManager = NianticManager.getInstance();
    locationManager.register(new LocationManager.Listener() {

        @Override
        public void onLocationChanged(Location location) {
            if (mLocation == null) {
                mLocation = location;
                initMap(true, true);
            } else {
                mLocation = location;
            }
        }

        @Override
        public void onLocationFetchFailed(@Nullable ConnectionResult connectionResult) {
            showLocationFetchFailed();
        }
    });
    // Inflate the layout for this fragment if the view is not null
    if (mView == null)
        mView = inflater.inflate(R.layout.fragment_map_wrapper, container, false);
    else {
    }
    // build the map
    if (mSupportMapFragment == null) {
        mSupportMapFragment = SupportMapFragment.newInstance();
        getChildFragmentManager().beginTransaction().replace(R.id.map, mSupportMapFragment).commit();
        mSupportMapFragment.setRetainInstance(true);
    }
    if (mGoogleMap == null) {
        mSupportMapFragment.getMapAsync(this);
    }
    FloatingActionButton locationFab = (FloatingActionButton) mView.findViewById(R.id.location_fab);
    locationFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mLocation != null && mGoogleMap != null) {
                mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLocation.getLatitude(), mLocation.getLongitude()), 15));
            } else {
                showLocationFetchFailed();
            }
        }
    });
    mView.findViewById(R.id.closeSuggestions).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            hideMapSuggestion();
        }
    });
    if (!mPref.getShowMapSuggestion()) {
        hideMapSuggestion();
    }
    return mView;
}
Also used : LocationManager(com.omkarmoghe.pokemap.controllers.map.LocationManager) ConnectionResult(com.google.android.gms.common.ConnectionResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View) Location(android.location.Location)

Aggregations

Location (android.location.Location)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 View (android.view.View)1 ConnectionResult (com.google.android.gms.common.ConnectionResult)1 LatLng (com.google.android.gms.maps.model.LatLng)1 LocationManager (com.omkarmoghe.pokemap.controllers.map.LocationManager)1