【问题标题】:Current location Detail Google Maps当前位置 详情 谷歌地图
【发布时间】:2017-08-27 11:08:54
【问题描述】:

我已经实现了一个应用程序,可以显示地图上的当前位置。我有我所在位置的坐标。我们有 Places api Web 服务,但它是 11.2.0 版本,我的项目有 10.2.0 gms 服务版本。 我该怎么做才能获得我的位置地址?

我已经实现了一个功能,但似乎没有任何效果。

void getPlaceDetail() {
    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
                .getCurrentPlace(googleApiClient, null);

        result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
            @Override
            public void onResult(PlaceLikelihoodBuffer placeLikelihoods) {

                for (PlaceLikelihood placeLikelihood : placeLikelihoods) {
                    et.setText(placeLikelihood.getPlace().getAddress());
                }

                placeLikelihoods.release();
            }
        });
    }

}

【问题讨论】:

    标签: android google-maps android-maps


    【解决方案1】:

    我找到了问题的答案。

    void getPlaceDetail(LatLng currLatLng) {
        Geocoder geocoder= new Geocoder(getActivity());
        try {
            if(currLatLng == null ) return;
            List<Address> address= geocoder.getFromLocation(currLatLng.latitude, currLatLng.longitude, 1);
            et.setText(address.get(0).getAddressLine(0) +" "+ address.get(0).getAddressLine(1));
    
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 2014-08-21
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多