Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. {
  2. "results" : [
  3. {
  4. "address_components" : [
  5. {
  6. "long_name" : "1200",
  7. "short_name" : "1200",
  8. "types" : [ "street_number" ]
  9. },
  10. {
  11. "long_name" : "2402",
  12. "short_name" : "2402",
  13. "types" : [ "postal_code_suffix" ]
  14. }
  15. ],
  16. "formatted_address" : "abc, City, State 123, country",
  17. "geometry" : {
  18. "bounds" : {
  19. "northeast" : {
  20. "lat" : 41.8683573,
  21. "lng" : -87.6126831
  22. },
  23. "southwest" : {
  24. "lat" : 41.86688609999999,
  25. "lng" : -87.6146402
  26. }
  27. },
  28. "location" : {
  29. "lat" : 41.8676217,
  30. "lng" : -87.6136616
  31. },
  32.  
  33. },
  34. "place_id" : "ChIJny65eGMrDogRJ-qe3QJEuEo",
  35. "types" : [ "premise" ]
  36. }
  37. ],
  38. "status" : "OK"
  39. }
  40.  
  41. JSONParser parser = JSON.createParser(res.getBody());
  42. double l1 = null;
  43. double l2 = null;
  44.  
  45. while (parser.nextToken() != null) {
  46. System.debug('entred while');
  47. if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
  48. (parser.getText() == 'location')){
  49.  
  50. parser.nextToken();
  51. while (parser.nextToken() != JSONToken.END_OBJECT){
  52. String txt = parser.getText();
  53. parser.nextToken();
  54. if (txt == 'lat')
  55. l1 = parser.getDoubleValue();
  56. else if (txt == 'lng')
  57. l2 = parser.getDoubleValue();
  58. }
  59.  
  60. }
  61. }
  62. // i am storing values in Custom object
  63. if (l1 != null){
  64. customobj__c.Location__Latitude__s = l1;
  65. customobj__c.Location__Longitude__s = l2;
  66. update customobj__c;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement