如何在地图上显示地点可能性?

How to display placelikelihood on map?

List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME, Place.Field.LAT_LNG);


// Use the builder to create a FindCurrentPlaceRequest.

    FindCurrentPlaceRequest request =
            FindCurrentPlaceRequest.newInstance(placeFields);

// Call findCurrentPlace and handle the response (first check that the user has granted permission).

    if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        Task<FindCurrentPlaceResponse> placeResponse = placesClient.findCurrentPlace(request);
        placeResponse.addOnCompleteListener(task -> {
            if (task.isSuccessful()){
                FindCurrentPlaceResponse response = task.getResult();
                for (PlaceLikelihood placeLikelihood : response.getPlaceLikelihoods()) {

                    Log.i("TAG", String.format("Place '%s' has likelihood: %f",
                            placeLikelihood.getPlace().getName(),
                            placeLikelihood.getLikelihood()));
                }
            } else {
                Exception exception = task.getException();
                if (exception instanceof ApiException) {
                    ApiException apiException = (ApiException) exception;
                    Log.e(TAG, "Place not found: " + apiException.getStatusCode());
                }
            }
        });
    } else {

        // A local method to request required permissions;
        // See https://developer.android.com/training/permissions/requesting

        Log.i("TAG", "Turn on location on your device!");
    }

我想使用标记或现有的任何其他方式在地图上显示所有这些地点:

mMap.addMarker(new MarkerOptions().position(currentLoc).title("Marker in Birmingham"));

将得到的lat/lng保存为变量,例如:

latLng = placeLikelihood.getPlace().getLatLng()

然后按如下方式将其传递到标记中:

mMap.addMarker(new MarkerOptions().position(latLng))

资源:
https://developers.google.com/places/android-sdk/current-place#get-current
https://developers.google.com/maps/documentation/android-sdk/map-with-marker#add_a_map

希望对您有所帮助!