How to Implement Place Picker in Android App after Deprecation of previous Maps SDK

只谈情不闲聊 提交于 2020-01-05 08:11:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!