user11029823
user11029823

Reputation:

How can I use GoogleMap SDK to list nearby places?

I'm trying to implement Map activity. I need to show nearby places using Google map SDK. I don't know how to use Google Map SDK because I'm a beginner.

I try many tutorial all of that use HTTP URL. I need to use Google Map SDK. Near by places search with keywords like ATM, BANK etc with specified radius.

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private FusedLocationProviderClient fusedLocationClient;
    double C_Latitude, C_Longitude;
    PlacesClient placesClient;
    private static final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 1;
    String keyword="atm";
    String radius="1000"; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        Places.initialize(getApplicationContext(),"@string/key");
        placesClient = Places.createClient(this);
        fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {

        mMap = googleMap;
        if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            } else {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_READ_CONTACTS);
            }
        } else {
            fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
                    @Override
                    public void onSuccess(Location location) {
                        if (location != null) {
                            C_Latitude = location.getLatitude();
                            C_Longitude = location.getLongitude();
                            LatLng CurrntLocation = new LatLng(C_Latitude, C_Longitude);
                            CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(CurrntLocation, 19);  //zoom
                            mMap.addMarker(new MarkerOptions().position(CurrntLocation).title("Current Position"));  //marker
                            mMap.animateCamera(yourLocation);
                            GetNearbyPlace();
                        }
                    }
                });
        }
    }

    private void GetNearbyPlace() {

    }
}

Upvotes: 0

Views: 522

Answers (1)

Navin Kumar
Navin Kumar

Reputation: 4027

Google Places SDK is deprecated, please migrate to new PLACES API

https://developers.google.com/places/android-sdk/client-migration#place_picker

  • First you need enable PlacesAPI in developer console (you should enable billing account).
  • Then implement Places API in your gradle.

for Autocomplete Places follow below guideline

https://stackoverflow.com/a/55045772/10579969

Upvotes: 1

Related Questions