Google Maps on Android Studio

1

I download the information from the url in json and full variables

private static PostResponseAsyncTask task;

OnCreate

task = new PostResponseAsyncTask(this);
    task.execute(url_localizacion+Dispositivo);

I run the task in the url + methodGET

  @Override
public void processFinish(String s) {
    try {
        JSONArray jsonArray = new JSONArray(s);
        for (int i = 0; i < jsonArray.length(); i++) {
            Longitud = (jsonArray.getJSONObject(i).getString("longitud"));
            Latitud = (jsonArray.getJSONObject(i).getString("latitud"));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

Here my question is getting the Latitude and Longitude of the database data in the cloud but I am running the google map before.

@Override
public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;
    mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

    // Add a marker in Sydney and move the camera
    LatLng locMovil = new LatLng(parseDouble(Latitud),parseDouble(Longitud));
    mMap.addMarker(new MarkerOptions().position(locMovil).title(Dispositivo)); //Titulo de Marker
    //mMap.moveCamera(CameraUpdateFactory.newLatLng(locMovil));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(locMovil, (float) 16.0));
}

How can I first download the information from the cloud and then add the coordinates of the variables Longitud y Latitud ?

    
asked by DoubleM 28.12.2016 в 19:57
source

1 answer

1

What you can do is get the coordinates in your method and then call the onMapReady method with the following instruction:

tuSupportMapFragment.getMapAsync(this);

It would be something like this:

@Override
public void processFinish(String s) {
    try {
        JSONArray jsonArray = new JSONArray(s);
        for (int i = 0; i < jsonArray.length(); i++) {
            Longitud = (jsonArray.getJSONObject(i).getString("longitud"));
            Latitud = (jsonArray.getJSONObject(i).getString("latitud"));
        }
        tuSupportMapFragment.getMapAsync(this);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
    
answered by 28.12.2016 / 20:03
source