안녕하세요 GetLocation1 class 의 Log.d("lalo", laloList.toString()); 에 출력되는 내용을
MapsActivity class의 mMap.addPolyline((new PolylineOptions()).add(Brisbane, NewCastle, TamWorth).
에 넣어 mMap.addPolyline((new PolylineOptions()).add(laloList.toString()).
형식으로 사용하려고 합니다만 . 어떻게 하면될가요?
-----------------------------------------------------------------------------------------------------
public class GetLocation1 extends AsyncTask<String, Void, List<Lalo>> {
OkHttpClient client = new OkHttpClient();
public List<Lalo> doInBackground(String... params) {
List<Lalo> laloList = new ArrayList<>();
String strUrl = params[0];
try {
Request request = new Request.Builder()
.url(strUrl)
.build();
Response response = client.newCall(request).execute();
JSONArray jsonArray = new JSONArray(response.body().string());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String num = jsonObject.getString("num");
String email = jsonObject.getString("email");
String lati = jsonObject.getString("lati");
String longt = jsonObject.getString("longt");
String time = jsonObject.getString("time");
Lalo l = new Lalo(num, email, lati, longt, time);
laloList.add(l);
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return laloList;
}
@Override
public void onPostExecute(List<Lalo> laloList) {
super.onPostExecute(laloList);
if (laloList != null) {
Log.d("lalo", laloList.toString());
//laloList.toString();
}
}
}
__________________________________________________
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private List<Marker> mMarkers = new ArrayList<>();
private Polyline mPolyline;
private GoogleMap mMap;
private ActivityMapsBinding binding;
// below are the latitude and longitude of 4 different locations.
LatLng TamWorth = new LatLng(-31.083332, 150.916672);
LatLng NewCastle = new LatLng(-32.916668, 151.750000);
LatLng Brisbane = new LatLng(-27.470125, 153.021072);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GetLocation1 getLocation1 = new GetLocation1();
getLocation1.execute("https://json address");
Log.d("www", "2: ");
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// inside on map ready method
// we will be displaying polygon on Google Maps.
// on below line we will be adding polyline on Google Maps.
mMap.addPolyline((new PolylineOptions()).add(Brisbane, NewCastle, TamWorth).
// below line is use to specify the width of poly line.
width(5)
// below line is use to add color to our poly line.
.color(Color.RED)
// below line is to make our poly line geodesic.
.geodesic(true));
// on below line we will be starting the drawing of polyline.
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Brisbane, 13));
}
}