如何在android中实现Places和PlaceLikelihoodBuffer?
我需要导入/实现上述类,但似乎不能简单地编写如何在android中实现Places和PlaceLikelihoodBuffer?,android,google-maps,google-places,Android,Google Maps,Google Places,我需要导入/实现上述类,但似乎不能简单地编写 import com.google.android.gms.location.places.Places; import com.google.android.gms.location.places.PlaceLikelihoodBuffer; 如果我这样做,它表明这些问题无法解决。根据我之前遇到的情况,我怀疑我需要添加一些其他内容,比如在清单中,但我似乎找不到确切的内容 需要这些导入的代码如下所示,取自谷歌教程 PendingResult<
import com.google.android.gms.location.places.Places;
import com.google.android.gms.location.places.PlaceLikelihoodBuffer;
如果我这样做,它表明这些问题无法解决。根据我之前遇到的情况,我怀疑我需要添加一些其他内容,比如在清单中,但我似乎找不到确切的内容
需要这些导入的代码如下所示,取自谷歌教程
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
//@Override
public void onResult(@NonNull PlaceLikelihoodBuffer likelyPlaces) {
int i = 0;
mLikelyPlaceNames = new String[mMaxEntries];
mLikelyPlaceAddresses = new String[mMaxEntries];
mLikelyPlaceAttributions = new String[mMaxEntries];
mLikelyPlaceLatLngs = new LatLng[mMaxEntries];
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
// Build a list of likely places to show the user. Max 5.
mLikelyPlaceNames[i] = (String) placeLikelihood.getPlace().getName();
mLikelyPlaceAddresses[i] = (String) placeLikelihood.getPlace().getAddress();
mLikelyPlaceAttributions[i] = (String) placeLikelihood.getPlace()
.getAttributions();
mLikelyPlaceLatLngs[i] = placeLikelihood.getPlace().getLatLng();
i++;
if (i > (mMaxEntries - 1)) {
break;
}
}
// Release the place likelihood buffer, to avoid memory leaks.
likelyPlaces.release();
// Show a dialog offering the user the list of likely places, and add a
// marker at the selected place.
openPlacesDialog();
}
});
pendingreult结果=Places.PlaceDetectionApi
.getCurrentPlace(mgoogleapClient,空);
result.setResultCallback(新的ResultCallback(){
//@凌驾
public void onResult(@NonNull placeLikeLikeLihoodBuffer likelyPlaces){
int i=0;
mLikelyPlaceNames=新字符串[mMaxEntries];
mlikelyplacepateaddress=新字符串[mMaxEntries];
mlikelyplacetributes=新字符串[mMaxEntries];
mlikelyplacelngs=新车床[mMaxEntries];
for(place可能性place可能性:likelyPlaces){
//建立一个可能的位置列表,以显示用户。最多5个。
mLikelyPlaceNames[i]=(字符串)placelikelike.getPlace().getName();
MLIkelyReplaceAddresses[i]=(字符串)placelikelibility.getPlace().getAddress();
mlikelyplacetributes[i]=(字符串)placelikelike.getPlace()
.getAttributes();
mlikelyplacelngs[i]=placelikelibility.getPlace().getLatLng();
i++;
如果(i>(mMaxEntries-1)){
打破
}
}
//释放内存缓冲区,以避免内存泄漏。
likelyPlaces.release();
//显示一个对话框,向用户提供可能的位置列表,并添加
//标记在选定的位置。
openPlacesDialog();
}
});
您是否已将编译'com.google.android.gms:play services places:10.2.0'
添加到您的build.gradle
?我没有。非常感谢。