我使用此代码,我可以更改纬度和经度但是当我运行应用时,应用不会显示我的搜索详细信息
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);
如何解决这个问题?
答案 0 :(得分:1)
通过此代码,您可以根据自己的位置轻松获取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();
}
});