这是替代方案。
实施 'com.google.android.gms:play-services-places:16.1.0'
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Places.initialize(getApplicationContext(), getString(R.string.google_maps_key));
PlacesClient placesClient = Places.createClient(this);
mAutocompleteSupportFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.placeAutocompletefragment); // Fragment is declared in layout file
mAutocompleteSupportFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG));
mAutocompleteSupportFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(@NonNull Place place) {
Log.d("PlaceAddress", "onPlaceSelected: " + place.getLatLng());
LatLng queriedLocation = place.getLatLng();
Log.v("Latitude is", "" + queriedLocation.latitude);
Log.v("Longitude is", "" + queriedLocation.longitude);
mLat = queriedLocation.latitude;
mLng = queriedLocation.longitude;
}
@Override
public void onError(@NonNull Status status) {
}
});
在这里,您将获得所选地点的纬度。