0

I'm making an app that'll let someone look up for a doctor nearby(registered on Google maps) when they select the Locate option from the navigation drawer.

I've got the fragment with the google map inside it and have initialised it to currently load a particular latitude and longitude and added a Location button to point to user's current location.

However, what I'd like to do is when someone selects the "Locate" option from the navigation drawer the app should automatically load the user's current location and display a 5mile radius with the doctors on it.

I'm new to coding so I'm not sure how it is to be coded!

Here's my current fragment.java file

package com.test.drawernav;


import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


/**
 * A simple {@link Fragment} subclass.
 */
public class LocateFragment extends Fragment implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {



    public LocateFragment() {
        // Required empty public constructor
    }




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View mapView = inflater.inflate(R.layout.fragment_locate, container, false);

        return mapView;
    }


    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        SupportMapFragment mapFragment = (SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);



    }



    @Override
    public void onConnectionFailed(ConnectionResult arg0){

    }

    @Override
    public void onConnected(Bundle bundle) {


    }

    @Override
    public void onConnectionSuspended(int i) {

    }



    @Override
    public void onMapReady(GoogleMap googleMap) {

        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.6139, 77.2090), 12.0f));

       // googleMap.setMyLocationEnabled(true);

    }

}
Devansh
  • 141
  • 2
  • 15
  • possible duplicate - http://stackoverflow.com/questions/32393134/getting-results-of-nearby-places-from-users-location-using-google-maps-api-in-a – adjuremods Feb 29 '16 at 08:23

1 Answers1

0

Have you looked at Google Places API instead of Maps? This has specific places loaded onto a map and the built-in classes are very good. Each Place has LatLng, name and other descriptive information, and also has a List of place types - e.g in your case you could filter for Doctor, Hospital etc. and only these would be shown. Place Types

Mark
  • 535
  • 4
  • 13
  • Can you explain how it can be initialised? I added what's given here https://developers.google.com/places/android-api/start but it just loaded the default google maps view over Africa. – Devansh Feb 28 '16 at 10:30
  • Sorry I just re-read the docs for Place API and you can filter it by more general terms (only show cities or establishments) but not a specifc place type. – Mark Feb 28 '16 at 13:34