应用 我的应用程序在我当前位置附近显示标记(工作正常)。之后,此人可以单击标记,以便弹出描述该特定位置的窗口。一旦该人点击了弹出窗口,就会启动评论活动。
问题 我的评论活动显示用户关于该位置的姓名,地址,联系方式,网站,评级,评论。某些地方的一切都很好,但不适合某些地方。
这是我的Code.java
TextView addressText = (TextView) findViewById(R.id.addressText);
TextView contactText = (TextView) findViewById(R.id.contactText);
TextView websiteText = (TextView) findViewById(R.id.websiteText);
final JSONObject json = new JSONObject(result);
JSONObject completeDesc = json.getJSONObject("result");
addressText.setText(completeDesc.getString("vicinity"));
contactText.setText(completeDesc.getString("formatted_phone_number"));
websiteText.setText(completeDesc.getString("website"));
Double ratStar = completeDesc.getDouble("rating");
JSONArray photo = json.getJSONArray("photos");
JSONObject photoDesc = photo.getJSONObject(0);
String photoRef = photoDesc.getString("photo_reference");
checkStarCondition(ratStar);
LinearLayout layout = (LinearLayout) findViewById(R.id.reviewInfo);
JSONArray reviewArray = completeDesc.getJSONArray("reviews");
if ( reviewArray.length() > 0 ) {
TextView noReview = (TextView) findViewById(R.id.noReview);
noReview.setVisibility(View.GONE);
}
for (int i = 0; i < reviewArray.length(); ++i) {
TextView user = new TextView(ReviewActivity.this);
TextView comment = new TextView(ReviewActivity.this);
TextView linebreak = new TextView(ReviewActivity.this);
JSONObject jObj = reviewArray.getJSONObject(i);
final LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
user.setLayoutParams(lparams);
user.setText(jObj.getString("author_name"));
user.setTextSize(18);
user.setTypeface(null, Typeface.BOLD);
comment.setLayoutParams(lparams);
comment.setText(jObj.getString("text"));
comment.setTextSize(14);
linebreak.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
linebreak.setText(" ");
layout.addView(user);
layout.addView(comment);
layout.addView(linebreak);
}
} catch (JSONException e) {
e.printStackTrace();
}
review_activty.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mazik.ahmed.funkyproject.ReviewActivity"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/ic_store"
android:id="@+id/imageView" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ratingStar"
android:src="@drawable/star00" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:src="@drawable/ic_name"
android:id="@+id/imageView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="@+id/nameText"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:src="@drawable/ic_address"
android:id="@+id/imageView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Address"
android:id="@+id/addressText"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:src="@drawable/ic_call"
android:id="@+id/imageView5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Contact"
android:id="@+id/contactText"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:src="@drawable/ic_web"
android:id="@+id/imageView6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Website"
android:id="@+id/websiteText"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:padding="15dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28sp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Reviews"
android:id="@+id/reviewText" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/reviewInfo"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="No Review Available"
android:id="@+id/noReview"
android:textColor="#CCC"
android:textAlignment="center"
android:padding="20dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
我面临的问题是,对于某些地方来说,这个api获取的数据完全正常,但在某些情况下它在其他地方失败,即使谷歌地图显示该地点的评级和评论。
有人可以帮我解决我的错误吗?