2017-09-16 3 views
0

마커 정보를 textView로 가져오고 싶습니다.하지만 할 수 있습니다. JSON의 마지막 아이디어 만 보여줍니다. 문제를 해결하는 방법은 무엇입니까?Android Google지도 TextView에 마커 정보

내 계획은 사용자가 마커를 클릭 한 다음 RealitveLayout을 "가시적"으로 만들었지 만 지금까지는 작동하지만 내 마커는 JSON에서 수집 한 다음 광고를 MAP에,

트릭 만드는 것 온 클릭 리스너 (설정을 볼 레이아웃과 그 레이아웃에 어떤 텍스트 뷰 수있는 정보를 전송합니다.)

IT 작동 있습니다,하지만 그것은 단지 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); 

     } 
    };} 

내가

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(); 
     } 
    }); 

(URL에서) JSON에서 정보를 얻을 그리고 마커를 추가하면지도하는 방법 그게 :

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 

답변

0

는 구글 맵 마커 정보를 얻으려면 여기 내가 하나의 정의를 생성 정보 창

public class CustomWindowInfo implements GoogleMap.InfoWindowAdapter { 

// Use default InfoWindow frame 
@Override 
public View getInfoWindow(Marker arg0) { 
    return null; 
} 

// Defines the contents of the InfoWindow 
@Override 
public View getInfoContents(Marker arg0) { 

    // Getting view from the layout file info_window_layout 
    View v = getLayoutInflater().inflate(R.layout.custom_map_window, null); 
    TextView texttitle = (TextView) v.findViewById(R.id.texttitle); 
    TextView text_description = (TextView) v.findViewById(R.id.text_description); 

    texttitle.setText(arg0.getTitle()); 

    // Setting the location to the textview 
    text_description.setText(arg0.getSnippet()); 
    return v; 

}} 

구글지도

googleMap.setInfoWindowAdapter(new CustomWindowInfo()); 
googleMap.setOnInfoWindowClickListener(listenerInfowindow_click); 

과에 대한 사용자 정의 정보 창을 설정하면 클릭에 마커의 inforamtion에를 얻을 수

public GoogleMap.OnInfoWindowClickListener listenerInfowindow_click = new GoogleMap.OnInfoWindowClickListener() { 

     @Override 
     public void onInfoWindowClick(final Marker marker) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(MapActivity.this); 
      builder.setTitle(""); 
      builder.setMessage(dialog_mas); 
      builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 

        if (InterNet.isConnectedToInternet()) { 
        Geocoder selected_place_geocoder = new Geocoder(MapActivity.this); 
        address = selected_place_geocoder.getFromLocationName(marker.getSnippet(), 1); 

        } else { 
         Toast.makeText(MapActivity.this,InterNet.interNetMsg, Toast.LENGTH_LONG).show(); 
        } 
        dialog.cancel(); 
       } 
      }); 
      builder.setNegativeButton("N0", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 

       } 
      }); 
      builder.show(); 


     } 
    };