如何在地图上为每个JSONObject添加标记?

时间:2019-01-20 21:14:38

标签: java json google-maps

当我解析Lat和Lng时,我有一个int(i),它存储“有多少个JSONObjects”和Lat,而Lng是依赖于它们所属的JSONObject的值,即“ i”和由于从云请求数据,JSONObject会不断更新。我想知道如何为每个JSONObject创建Map Markers,因为值彼此不同(JSONObject)。

for (int i = 0; i < main_array.length(); i++) {

    JSONObject obj = main_array.getJSONObject(i);
    JSONArray ar = obj.getJSONArray("coordinates");

    for (int j = 0; j < ar.length(); j++) {
        String co = ar.getString(i);
        String[] latlong = co.split(",");
        double latitude = Double.parseDouble(latlong[0]);
        double longitude = Double.parseDouble(latlong[1]);
        //below this is where I have to add a marker for each JSONObject (i) and that's where I'm having trouble
        LatLng marker = new LatLng(latitude, longitude);
        mMap.addMarker(new MarkerOptions().position(marker).title("Corte de calle"));
    }
}

我希望代码为从其检索数据的JSONObjects中的每个坐标添加多个标记。

0 个答案:

没有答案