我使用此代码,我可以更改纬度和经度但是当我运行应用程序时,应用程序不会显示我的搜索详细信息
private ArrayList<MyGooglePlaces> getPredictions(String constraint)
{
//pass your current latitude and longitude to find nearby and ranky=distance means places will be found in ascending order
// according to distance
double latitude=30.7333;
double longitude=76.7794;
String API_KEY="AIzaSyByodZEsDBTC-J3brJ39JiYTkqbtJhlSKo";
String url= "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+latitude+","+longitude+"&rankby=distance&name="+constraint+"&key="+API_KEY;
return getPlaces(url);
我该如何解决这个问题?
根据您的位置,您可以通过此代码轻松获取Google地图上列出的附近地点列表。
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
ArrayList<String> nearbyPlaces = new ArrayList<>();
for (final PlaceLikelihood placeLikelihood : likelyPlaces) {
nearbyPlaces.add(placeLikelihood.getPlace().getName().toString());
// here, placeLikelihood.getPlace().getName() returns name of nearby places
}
likelyPlaces.release();
}
});