2014-02-12 2 views
0

내 문제에 대한 해결책을 찾고 있는데 일부 정보를 찾았습니다. here하지만 내 코드에서 작동하지 않을 수 있습니다.추가/사용자 지정지도 표식 값 만들기

그래서 마커가있는 Google지도가 있습니다. 마커는 JSON 정보로 만들어집니다. 내가 원하는 것은 각 마커에 맞춤 값을 첨부하는 것입니다. 따라서 사용자가 infowindow을 터치 할 때마다 특정 마커에 첨부 된 전달 된 매개 변수로 새로운 활동이 열립니다. 여기

는 JSON 파싱 마커 창조 :

사용자가 마커 접촉하므로 마커 여분 파라미터, 즉 이미지를 할당하는 방법을
try{ 
       JSONArray jArray = new JSONArray(result); 
       for(int i=0; i < jArray.length(); i++) { 
         JSONObject jObject = jArray.getJSONObject(i); 

         String image = jObject.getString("image"); 
         String title = jObject.getString("title"); 
         String snipet = jObject.getString("snipet"); 

         double lat=jObject.getDouble("lat"); 
         double lng=jObject.getDouble("lng"); 

         addMarkers(lat, lng,image,title,snipet); 
        } // End Loop 
       } catch (JSONException e) { 
        Log.e("JSONException", "Error: " + e.toString()); 
       } // catch (JSONException e) 

private void addMarkers(double jLat, double jLng, final String image, final String jTitle,final String jDescription) 
    { 
    LatLng jLocation = new LatLng(jLat, jLng); 

    alertMarkers = theMap.addMarker(new MarkerOptions() 
        .position(jLocation) 
        .title(jTitle) 
        .snippet(jDescription) 
        .icon(BitmapDescriptorFactory.fromResource(icon))); 
     theMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
       @Override 
       public void onInfoWindowClick(Marker arg0) { 
       Toast.makeText(MainActivity.this, arg0.getId(), 1000).show(); 
    }} 

    } 

해당 이미지는 추가 처리에 사용될 .

감사합니다.

편집 : 나는 위의 코드에 추가하지만, 뭔가 옳지 않다 여기에서

:

*alertMarkers = theMap.addMarker(new MarkerOptions() 
         .position(jLocation) 
         .title(jTitle) 
         .snippet(jDescription) 
         .icon(BitmapDescriptorFactory.fromResource(icon)));* 

HashMap<String, Integer> data = new HashMap<String, Integer>(); 
data.put("id",alertID); 
extraMarkerInfo.put(alertMarkers.getId(),data); 

public void onInfoWindowClick(Marker arg0) { 
       HashMap<String, String> marker_data = extraMarkerInfo.get(arg0.getId()); 
       Log.i("test",marker_data.get("id")); 
(…) 
: 가 시작 선언
HashMap<String, HashMap> extraMarkerInfo = new HashMap<String, HashMap>(); 

은 새로운 HashMap에 추가

하지만 오류가 발생합니다 :

라인에서3210
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String 

:

  HashMap<String, String> marker_data = extraMarkerInfo.get(arg0.getId()); 

나는 HashMaps을 가진 조금 혼란 스러워요.

답변

2

HashMap<> (시스템에서 생성 한 불변) the ID value of the Marker을 해당 추가 데이터에 그대로 유지할 수 있습니다. 그런 다음 마커 탭에서 추가 데이터를 찾습니다. this sample project에서 실제로이를 볼 수 있습니다.

또는 데이터 (JSON)의 문자열 표현을 Marker의 스 니펫으로 이동하고 필요에 따라 나중에 다시 검색 할 수 있습니다. 더 많은 오버 헤드가 될 것 같습니다.

Marker 그러나 final이며 확장 할 수 없습니다.

+0

정보를 주셔서 감사합니다. 지금 샘플 프로젝트를보고 있습니다. – Theodoros80

+0

다른 아이디어 또는 샘플 코드? – Theodoros80