내 문제에 대한 해결책을 찾고 있는데 일부 정보를 찾았습니다. here하지만 내 코드에서 작동하지 않을 수 있습니다.추가/사용자 지정지도 표식 값 만들기
그래서 마커가있는 Google지도가 있습니다. 마커는 JSON 정보로 만들어집니다. 내가 원하는 것은 각 마커에 맞춤 값을 첨부하는 것입니다. 따라서 사용자가 infowindow
을 터치 할 때마다 특정 마커에 첨부 된 전달 된 매개 변수로 새로운 활동이 열립니다. 여기
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에 추가
하지만 오류가 발생합니다 :
라인에서3210java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
:
HashMap<String, String> marker_data = extraMarkerInfo.get(arg0.getId());
나는 HashMaps을 가진 조금 혼란 스러워요.
정보를 주셔서 감사합니다. 지금 샘플 프로젝트를보고 있습니다. – Theodoros80
다른 아이디어 또는 샘플 코드? – Theodoros80