java - 如何使用retrofit2在地图中搜索标记?
问题描述
我在 Maps Android Google Maps API 中的 foreach 标记有问题
我试过使用 ArrayList foreach,但地图上的标记仍然没有出现,也许我的语法有错误
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}
我的期望是标记出现在上面的 lat 和 long JSON 响应的地图上
解决方案
假设 nMap 已经初始化,我相信你的 mMap.addMarker 应该在循环内而不是在循环外。你能检查一下吗?
推荐阅读
- javascript - 如何使用 react-redux 实现 addItem
- wso2 - 是否可以在 WSO2IS 中更改用户名正则表达式验证
- javascript - 在 localStorage 中添加了额外的项目?
- php - 将帖子缩略图 timage 附加到第一个内容标题标签
- laravel - 我需要的是显示所有用户的复选框,无论他们是否有 laravel 8 的特色帖子
- css - 如何使粘性元素可滚动?
- python - 如何将 Django 日期选择器格式化为 ISO 8601?
- javascript - 如何在 React Native Expo 中将图像保存到媒体库
- docker - 由于中间图像,Dockerfile 未将 clamav 定义存储到卷
- plotly - Plotly Sankey 恒定链接厚度