首页 > 解决方案 > Android Google Places Api 评级为空

问题描述

我正在使用以下代码从当前用户那里获取特定的附近地点。虽然我得到了我想要的一切,但我无法获得评级。它总是返回 null。我究竟做错了什么?

private void ShowNearbyPlaces(List<HashMap<String, String>> nearbyPlacesList) {
    for (int i = 0; i < nearbyPlacesList.size(); i++) {
        Log.d("onPostExecute", "Entered into showing locations");
        MarkerOptions markerOptions = new MarkerOptions();
        HashMap<String, String> googlePlace = nearbyPlacesList.get(i);
        double lat = Double.parseDouble(Objects.requireNonNull(googlePlace.get("lat")));
        double lng = Double.parseDouble(Objects.requireNonNull(googlePlace.get("lng")));
        String placeName = googlePlace.get("place_name");
        String vicinity = googlePlace.get("vicinity");
        String openNow = googlePlace.get("open_now");
        String rating = googlePlace.get("rating");
        Log.d("ShowNearbyPlaces", "GOOGLE PLACE :" + openNow);
        String openFlag = googlePlace.get("openFlag");
        String isOpen;
        if (openNow == "true") {
            isOpen = "open";
            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
        } else if (openNow == "false" && openFlag == "true") {
            isOpen = "closed";
            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
        } else {
            isOpen = "N/A";
            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
        }
        if (rating != null){
            if (rating.isEmpty()) {
                rating = "N/A";
            }
        }
        else
            rating = "N/A";
        LatLng latLng = new LatLng(lat, lng);
        markerOptions.position(latLng);
        markerOptions.title("NAME: " + placeName + "\nSTREET: " + vicinity + "\nSTATUS: " + isOpen +"\nRATING: "+rating);

        mMap.addMarker(markerOptions);

    }
}

标签: androidgoogle-places-api

解决方案


推荐阅读