Я сделал «Активность Google Maps» в Android Studio, но для добавления маркеров я использую JSON. (мое первое время с использованием JSON)Android Studio - данные JSON
В основном, когда открываются карты google, он загружает «маркер» в местоположении (String strJson), который содержит данные. Маркер отображает имя и страну, но я не могу заставить работать «latlng». Я пытался ...
Int latlng = Integer.parseInt(jsonObject.optString("latlng").toString());
Но «gMap.addMarker» не позволяет «Int»
Кто-нибудь знает, как я мог это сделать?
КОД:
String strJson= "{\"Location\" :[{\"name\":\"Gladiator Fitness\",\"latlng\":[\"53.2286362\",\"-0.5856869\"],\"country\":\"GB\"}]}";
try {
JSONObject jsonRootObject = new JSONObject(strJson);
//Get the instance of JSONArray that contains JSONObjects
JSONArray jsonArray = jsonRootObject.optJSONArray("Location");
//Iterate the jsonArray and print the info of JSONObjects
for(int i = 0; i < jsonArray.length(); i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
//Search the database for the "data"
String name = jsonObject.optString("name").toString();
String country = jsonObject.optString("country").toString();
//Add marker for each location
gMap.addMarker(new MarkerOptions().position(new LatLng(53.2286362,-0.5856896)).title(name).snippet(country));
}
Here скриншот того же кода. Спасибо заранее.
показать нам da coooode – Blundell
Да, пожалуйста, введите код непосредственно в вопрос. – ToothlessRebel