3

I want to add my own place using Google places API in android with some description. Now i want to add vicinity, URL, Website, international_phone_number etc in the string format below but i am unable to get it plz 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\" " +"}";
1
  • Can you post the error or issue associated with this?
    – Jack
    Commented Oct 30, 2012 at 15:19

1 Answer 1

1

Why are you using a string to treat JSON. While you could just use a 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");    

Not the answer you're looking for? Browse other questions tagged or ask your own question.