0

I am a newbie to android development. I want to develop an app which have three tabs.

  1. First tab will be My Location in which there is a map and a pin which is marking my location
  2. On second tab there will be a camera option, through which i can take pictures and those pictures will be saved in the memory located by OS to the app.
  3. The saved pictures will be shown in a slider

As for 2 and 3, i'll have some idea but for 1 i couldn't find any help. I did find some tutorials but all of them are for eclipse but i am using android studio.

During a study i found that Fragment is a way to do it so i started to follow this tutorial, but as i said earlier i am newbie and all tutorials are for eclipse.

Update 1

I have created 3 classes and 3 layout files each for each tab, bellow is the class for MyLocation tab

public class MyLocation extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.my_location, container, false);


    return rootView;
 }   } 

I am stuck to it now and don't know what to do

Any help would be highly appreciated

Moeez
  • 494
  • 9
  • 55
  • 147

1 Answers1

0

If you want to create google map inside fragment than go threw this code

public class GoogleMapFragment extends Fragment implements OnMapReadyCallback,
    GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{

private GoogleMap googleMap;
GoogleApiClient mGoogleApiClient;
Location mLastLocation;


@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_demo, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }
    mGoogleApiClient.connect();
}

@Override
public void onResume() {
    super.onResume();
    intiGoogleMap();
}

@Override
public void onStart() {
    mGoogleApiClient.connect();
    super.onStart();
}

@Override
public void onStop() {
    mGoogleApiClient.disconnect();
    super.onStop();
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    SupportMapFragment supportMapFragment = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapMapAddress));
    if (supportMapFragment != null)
        getFragmentManager().beginTransaction().remove(supportMapFragment).commit();
}

private void intiGoogleMap() {
    SupportMapFragment supportMapFragment = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapMapAddress));
    supportMapFragment.getMapAsync(this);
}


@Override
public void onConnected(@Nullable Bundle bundle) {
    //First check permissions if accept or reject
    if (AppUtils.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, getActivity()) &&
            AppUtils.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION, getActivity())) {
        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);
        if (googleMap != null)
            if (mLastLocation != null) {
               //here you can place your marker
            }
    } else {
        Toast.makeText(getActivity(), "Check your permission", Toast.LENGTH_LONG).show();
    }
}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}

@Override
public void onMapReady(GoogleMap googleMap) {
    if (googleMap != null) {
        this.googleMap = googleMap;
        this.googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        this.googleMap.getUiSettings().setCompassEnabled(true);
    }
}

}

and fragment_demo.xml is

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/mapMapAddress"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

and try to run this will be showing of google map, and make sure all permissions and you have created app in google developer console. Also make sure adding Android Key in manifest file.

Mohit Suthar
  • 8,725
  • 10
  • 37
  • 67
  • I do add a fragment, but it was giving me UI error. – Moeez Jan 27 '17 at 05:41
  • Can you please look into my new question http://stackoverflow.com/questions/41875474/google-map-doesnt-load-into-my-app-device – Moeez Jan 27 '17 at 05:41