android 高德地圖marker連線
阿新 • • 發佈:2018-12-11
@Override public void getRouteEquipment(final AMap aMap, String signature, String echostr, String timestamp, final Context context, final IscView iscView, String route, final FrameLayout fl_other) { requestQueue = Volley.newRequestQueue(context); final MyStringRequest stringrequest = new MyStringRequest(Request.Method.GET, "http://***********?signature=" + signature + "&echostr=" + echostr + "×tamp=" + timestamp + "&method=getElements&filter=Route&route=" + route, new Response.Listener<String>() { @Override public void onResponse(String s) { try { android.util.Log.d("getRouteEquipment", s); JSONArray jsonArray = new JSONArray(s); List<RouteLine> list_routeline = new ArrayList<RouteLine>(); List<LatLng> latLngs = new ArrayList<LatLng>(); if (jsonArray.length() > 0) { aMap.clear(); fl_other.setVisibility(View.GONE); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); getEquipmentIcon(jsonObject.getString("iconName"), jsonObject.getString("status"), jsonObject, iscView, true, (i + 1) + "",null); latLngs.add(new LatLng(Double.parseDouble(jsonObject.getString("latitude")), Double.parseDouble(jsonObject.getString("longitude")))); LatLng latLng = new LatLng(Double.parseDouble(jsonObject.getString("latitude")), Double.parseDouble(jsonObject.getString("longitude"))); aMap.addPolyline(new PolylineOptions(). addAll(latLngs).width(11).color(Color.parseColor("#6584f4"))); } /* aMap.addPolygon(new PolygonOptions().addAll(latLngs).strokeWidth(15) // 多邊形的邊框 .strokeColor(Color.parseColor("#f59208")) // 邊框顏色 .fillColor(Color.parseColor("#FFFFFF")));*/ } else { Toast.makeText(context, "沒有資料", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { android.util.Log.d("initVolley", volleyError.getMessage() + ""); } }); requestQueue.add(stringrequest); }
@Override public void getEquipmentIcon(String iconNme, String iconStatus, JSONObject jsonObject, IscView iscView, Boolean textShow, String text,final AMap aMap) { if (iconNme != null && !"".equals(iconNme)) { try { android.util.Log.d("description",jsonObject.getString("description").equals("")?"true":"false"); String categoryCode=jsonObject.getString("categoryCode"); String categoryName= jsonObject.getString("categoryName"); String location=jsonObject.getString("location"); String status=jsonObject.getString("status"); String description=jsonObject.getString("description"); if(null==categoryCode || "".equals(categoryCode)){ categoryCode="沒資料"; } if(null==location || "".equals(location)){ location="沒資料"; } if(null==status || "".equals(status)){ status="沒資料"; } if(null==description || "".equals(description)){ description="沒資料"; } if(null==categoryName || "".equals(categoryName)){ categoryName=""; } switch (iconNme) { case "SMALL-24G-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.a24g0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.a24g1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.a24g2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-FKJ-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.visitoreq0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.visitoreq1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.visitoreq2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-WIFI-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.wifi0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.wifi1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.wifi2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-BP-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.classband0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.classband1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.classband2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-DZ-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.break0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.break1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.break2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-QQDH-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.phone0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.phone1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.phone2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-SXT-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.camera0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.camera1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.camera2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-XYMT-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.doorman0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.doorman1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.doorman2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; case "SMALL-EWM-ICON": if (iconStatus != null && !"".equals(iconStatus)) { switch (iconStatus) { case "0": iscView.geticonName(R.drawable.qr0, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "1": iscView.geticonName(R.drawable.qr1, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; case "2": iscView.geticonName(R.drawable.qr2, jsonObject.getString("latitude"), jsonObject.getString("longitude"), categoryCode + ":" +categoryName + ":" + location + ":" + status + ":" + description, textShow, text); break; default: break; } } break; default: break; } } catch (Exception e) { e.printStackTrace(); } } }
//自定會圖片和自定義marker佈局
@Override public void geticonName(int iconId, String latitude, String longitude, String categoryCode,Boolean textShow,String text) { if(textShow){ //自定義marker佈局和圖片 aMap.addMarker(new MarkerOptions() .snippet(categoryCode) .draggable(false) // .icon(BitmapDescriptorFactory.fromResource(iconIgetMarkerViewd)) .icon(BitmapDescriptorFactory.fromBitmap(getMarkerView(iconId,text))) .position(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))); }else{ //自定義marker圖片 Log.d("iconIds",""+categoryCode); // Bitmap bm=getMarkerViewone(iconId); // if(bm != null && !"".equals(bm)) { aMap.addMarker(new MarkerOptions() .snippet(categoryCode) .draggable(false) // .icon(BitmapDescriptorFactory.fromBitmap(bm)) .icon(BitmapDescriptorFactory.fromResource(iconId)) .position(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))); } // } }
//自定義佈局轉換為bitmap
Bitmap getMarkerView(int iconId,String text){
View view = this.getLayoutInflater().inflate(R.layout.gaode_marker_item,
null);
ImageView im_marker = (ImageView) view.findViewById(R.id.im_marker);
TextView tv_marker = (TextView) view.findViewById(R.id.tv_marker);
im_marker.setImageResource(iconId);
tv_marker.setText(text);
Bitmap bitmap = convertViewToBitmap(view);
return bitmap;
}
Bitmap getMarkerViewone(int iconId){
View view = this.getLayoutInflater().inflate(R.layout.gaode_marker_item_one,
null);
ImageView im_marker = (ImageView) view.findViewById(R.id.im_marker);
im_marker.setImageResource(iconId);
Bitmap bitmap = convertViewToBitmap(view);
return bitmap;
}
效果