@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { MarkerFile.fileRead(); } catch (IOException e) { e.printStackTrace(); } buildGoogleApiClient(); }
public void viewMarkers() throws JSONException { JSONArray jsonArray; jsonArray = new JSONArray(MarkerFile.getMarkersData()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); mMap.addMarker( new MarkerOptions() .title(jsonObj.getString("name")) .snippet(jsonObj.getJSONObject("content").toString()) .position( new LatLng( jsonObj.getJSONArray("latlng").getDouble(0), jsonObj.getJSONArray("latlng").getDouble(1)))); } }
@Override public void onMapLongClick(LatLng latLng) { try { JsonParser.snippetOBJ.put("clean", "clean"); } catch (JSONException e) { e.printStackTrace(); } MarkerOptions marker; marker = new MarkerOptions() .title("New marker at " + latLng.toString()) .position(latLng) .snippet(String.valueOf(JsonParser.snippetOBJ)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); mMap.addMarker(marker); outputDataToFile = JsonParser.parseToOutput(JsonParser.snippetOBJ, marker).toString(); MarkerFile.fileWrite(outputDataToFile); }