将当前位置设置在 google 位置 api
Set the current place on google place api
我正在尝试使用 google place
api 搜索 Latlng
附近的地点(如餐馆或旅馆)。是否有可能更改 Places.PlaceDetectionApi getCurrentPlace(mGoogleApiClient, pf);
的结果并设置其他坐标。我的代码是:
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
ArrayList<String> restrictToRestaurants = new ArrayList<>();
restrictToRestaurants.add(Integer.toString(Place.TYPE_RESTAURANT));
PlaceFilter pf;
pf = new PlaceFilter(false, restrictToRestaurants);
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, pf);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
final CharSequence thirdPartyAttributions = likelyPlaces.getAttributions();
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i("tag", String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
所以我有一个变量 Latlng
,我想搜索靠近该坐标的地方。提前致谢。
嗯,你总是可以使用 Google Places API Web Service,它看起来像这样:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&keyword=cruise&key=API_KEY
其中
location — The latitude/longitude around which to retrieve place information. This must be specified as latitude,longitude.
我正在尝试使用 google place
api 搜索 Latlng
附近的地点(如餐馆或旅馆)。是否有可能更改 Places.PlaceDetectionApi getCurrentPlace(mGoogleApiClient, pf);
的结果并设置其他坐标。我的代码是:
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
ArrayList<String> restrictToRestaurants = new ArrayList<>();
restrictToRestaurants.add(Integer.toString(Place.TYPE_RESTAURANT));
PlaceFilter pf;
pf = new PlaceFilter(false, restrictToRestaurants);
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, pf);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
final CharSequence thirdPartyAttributions = likelyPlaces.getAttributions();
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i("tag", String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
所以我有一个变量 Latlng
,我想搜索靠近该坐标的地方。提前致谢。
嗯,你总是可以使用 Google Places API Web Service,它看起来像这样:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&keyword=cruise&key=API_KEY
其中
location — The latitude/longitude around which to retrieve place information. This must be specified as latitude,longitude.