0
我想讓我的標記信息textView,我能夠做到這一點,但它始終只顯示從JSON的最後一個,任何好主意如何解決?安卓谷歌地圖標記信息到TextView
我的計劃是很容易,當標記用戶點擊話反而會使得RealitveLayout「可見」,它的工作原理,到目前爲止,但我的問題是,我收集我的標記從JSON,然後廣告他們的MAP,
有聽者的OnClick什麼使的伎倆 (設置佈局可見和發送信息給TextView的什麼是對的佈局。)
它的工作原理,但只用了最後一個對象從JSON數組。
public GoogleMap.OnInfoWindowClickListener getInfoWindowClickListener()
{
return new GoogleMap.OnInfoWindowClickListener()
{
@Override
public void onInfoWindowClick(Marker marker)
{
RelativeLayout rl1 = (RelativeLayout) findViewById(R.id.popup);
rl1.setVisibility(View.VISIBLE); // Set the View to VISIBLE
//Title to TextView (also "Score" info)
TextView pealkiriTextView = (TextView) findViewById(R.id.pealkiriTextView);
pealkiriTextView.setText(title + " (" + punkte + " punkti)");
//Description to TextView
TextView pKirlejdusTextView = (TextView) findViewById(R.id.pKirlejdusTextView);
pKirlejdusTextView.setText(kirjeldus);
}
};}
這就是我如何獲取信息從JSON(從URL)
private void getMarkers() {
StringRequest strReq = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("Response: ", response.toString());
try {
JSONObject jObj = new JSONObject(response);
String getObject = jObj.getString("punktid");
JSONArray jsonArray = new JSONArray(getObject);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
nr = jsonObject.getString(NR);
title = jsonObject.getString(TITLE);
kirjeldus = jsonObject.getString(KIRJELDUS);
vahend = jsonObject.getString(VAHEND);
punkte = jsonObject.getString(PUNKTE);
latLng = new LatLng(Double.parseDouble(jsonObject.getString(LAT)), Double.parseDouble(jsonObject.getString(LNG)));
// Anname addMarkerile väärtused
addMarker(latLng, title, kirjeldus,punkte, nr, vahend);
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error: ", error.getMessage());
Toast.makeText(kaart.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
});
並添加標記到地圖:
private void addMarker(LatLng latlng,final String nr, final String title, final String kirjeldus,final String punkte, final String vahend) {
markerOptions.position(latlng);
//markerOptions.title(title +"(" + punkte +"p)");
markerOptions.title(punkte +" Punkti");
//markerOptions.snippet(kirjeldus);
if (vahend.equalsIgnoreCase("auto")) { markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.auto));
} else { markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.jala)); }
gMap.addMarker(markerOptions);} //addMarker