任何人都可以解释如何在Android的谷歌地图上显示多个标记使用以下JSON代码?如何在地图上显示多个标记
[
{"id":"1","lat":"18.105917","lng":"78.838325","location":" Laxmi Filling Station(Medak Road)","distance":"0"},
{"id":"3","lat":"18.105952","lng":"78.840366","location":"Fathima Filling Station (Medak Road)","distance":"0.1340667689594937"},
{"id":"13","lat":"18.093713","lng":"78.843775","location":"Thirumala Thirupathi Filling Station (Ensanpally Road)","distance":"0.9160924683870764"},
{"id":"12","lat":"18.101497","lng":"78.852353","location":"MS Balaji Filling Station (Old Busstand)","distance":"0.9706182480093937"}
]
所有的错误都解决仍然标记的没有显示在地图上
private void createMarkersFromJson(String json) throws JSONException {
// De-serialize the JSON string into an array of city objects
JSONArray jsonArray = new JSONArray(json);
for (int i = 0; i < jsonArray.length(); i++) {
// Create a marker for each city in the JSON data.
JSONObject jsonObj = jsonArray.getJSONObject(i);
String location=jsonObj.getString("location");
double lat=jsonObj.getDouble("lat");
double lng=jsonObj.getDouble("lng");
String id=jsonObj.getString("id");
Log.e("detailes", lat+" "+lng+" "+location);
map.addMarker(new MarkerOptions()
.title(location)
.snippet(id)
.position(new LatLng(lat, lng))
);
}
}
什么你试过到目前为止并编码没有为你工作? –
json数组不匹配异常是我得到的错误 –
我认为你犯了一个错误,以得到经纬度数组。检查jsonObj.getJSONArray(“latlng”)和jsonObj.getJSONArray(“latlng”)。 –