在google place api上设置当前位置

时间:2015-05-30 17:28:10

标签: java android google-maps google-play-services google-places-api

我尝试使用Latlng api搜索google place周围的地方(如餐馆或酒店)。是否有可能更改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,我想搜索几乎那个坐标的地方。提前谢谢。

1 个答案:

答案 0 :(得分:0)

嗯,你总是可以使用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 - 要检索地点信息的纬度/经度。必须将其指定为纬度,经度。