Adding a description when adding your own place using the Google Places API on Android
I want to add my own place using google places API in android with some description. Now I want to add neighborhood, url, website, international_phone_number, etc. Into the string format below, but I can't seem to get it to help me:
String placeJSON =
"{"+
"\"location\": {" +
"\"lat\": " + lat + "," +
"\"lng\": " + lng +
"}," +
"\"accuracy\":50.0," +
"\"name\": \"" + name + "\"," +
"\"types\": [\"" + type + "\"]," +
"\"vicinity\":\""+ DescriptionDialog.vic +"\","+
"\"formatted_address\":\""+ DescriptionDialog.formtd_address +"\","+
"\"formatted_phone_number\":\""+ DescriptionDialog.formtd_phone_number +"\","+
"\"url\":\""+ DescriptionDialog.myUrl +"\","+
"\"website\":\""+ DescriptionDialog.myWebsite +"\","+
"\"language\": \"en\" " +"}";
+3
source to share
1 answer
Why are you using string to process JSON. Although you can just use JSONObject and that should solve your problem.
JSONObject placeJson = new JSONObject();
JSONObject location = new JSONObecjt();
location.put("lat", lat);
location.put("lon", lon);
placeJson.put("location", location);
placeJson.put("accuracy", 50.0);
placeJson.put("types", types);
placeJson.put("vicinity", DescriptionDialog.vic);
placeJson.put("formatted_address", DescriptionDialog.formtd_address);
placeJson.put("formatted_phone_number", DescriptionDialog.formtd_phone_number);
placeJson.put("url", DescriptionDialog.myUrl);
placeJson.put("website" DescriptionDialog.myWebsite);
placeJson.put("language", "en");
+1
source to share