问题
I can't understand how I can implement a MapView with an indicator that returns Latitude and Longitude of a place marked by the user. (Just like the food delivery apps)
I am able to get the user's current latitude and longitude but not on MapView.
All online articles on the implementation of this type of Place Picker are obsolete and generate errors in some parts of the entire procedure.
I was unable to find any articles created after the old Maps SDK became obsolete.
This below is my noob coding:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity_second);
placepickerbutton = findViewById(R.id.placepickerbutton);
latlongtv = findViewById(R.id.showlatlong);
final FindCurrentPlaceRequest request = FindCurrentPlaceRequest.newInstance(placeFields);
Places.initialize(getApplicationContext(), apiKey);
final PlacesClient placesClient = Places.createClient(this);
if (ContextCompat.checkSelfPermission(MainActivity.this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Task<FindCurrentPlaceResponse> placeResponse = placesClient.findCurrentPlace(request);
placeResponse.addOnCompleteListener(new OnCompleteListener<FindCurrentPlaceResponse>() {
@Override
public void onComplete(@NonNull Task<FindCurrentPlaceResponse> task) {
if (task.isSuccessful()) {
FindCurrentPlaceResponse response = task.getResult();
for (PlaceLikelihood placeLikelihood : response.getPlaceLikelihoods()) {
Log.i("HERE IS THE LOCATION", String.format("Place '%s' has likelihood: %f",
placeLikelihood.getPlace().getLatLng(),
placeLikelihood.getLikelihood()));
}
} else {
Exception exception = task.getException();
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e("", "Place not found: " + apiException.getStatusCode());
}
}
}
});
} else {
// A local method to request required permissions;
// See https://developer.android.com/training/permissions/requesting
//getLocationPermission();
}
来源:https://stackoverflow.com/questions/58202065/how-to-implement-place-picker-in-android-app-after-deprecation-of-previous-maps