我在 Maps Android Google Maps API 中 foreach 标记时遇到问题
我尝试使用ArrayList foreach,但 map 上的标记仍然没有出现,也许我的语法有错误
private void Koordinat() {
Call<List<LatlongModel>> sektorCall = latlongInterface.GetLatlong();
sektorCall.enqueue(new Callback<List<LatlongModel>>() {
@Override
public void onResponse(Call<List<LatlongModel>> call, Response<List<LatlongModel>> response) {
if (response.isSuccessful() && response.body() != null) {
listLatlong = response.body();
ArrayList<Double> itemLatlong = new ArrayList<Double>();
for (int x = 0; x < response.body().size(); x++) {
Double latitude = response.body().get(x).getLatitude();
Double longitude = response.body().get(x).getLongitude();
itemLatlong.add(latitude);
itemLatlong.add(longitude);
latLongA = new LatLng(longitude, latitude);
}
mMap.addMarker(new MarkerOptions().position(latLongA)
.title("Citarum")
.snippet("Titik A")
.rotation((float) 3.5)
.icon(bitmapDescriptorFromVector(getApplicationContext(), R.drawable.ic_action_hijau)));
} else {
Toast.makeText(getBaseContext(), "response message"+ response.body().toString(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<List<LatlongModel>> call, Throwable t) {
t.printStackTrace();
}
});
}
标记来自以下 JSON 响应:
{"id": 1, "titk": "Titik A1", "lat": -6.9155332, "long": 107.4724021, "idSector": 1}
{"id": "1,"titk":"Titik A2","lat": -6.9153333,"long": 107.4725922,"idSector": 1}
我的期望是标记出现在上面的纬度和经度 JSON 响应的 map 上
最佳答案
假设 nMap 已经初始化,我相信你的 mMap.addMarker 应该位于循环内部而不是外部。你能检查一下吗?
关于java - 如何使用retrofit2查找 map 中的标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58592255/