Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "results" : [
- {
- "address_components" : [
- {
- "long_name" : "1200",
- "short_name" : "1200",
- "types" : [ "street_number" ]
- },
- {
- "long_name" : "2402",
- "short_name" : "2402",
- "types" : [ "postal_code_suffix" ]
- }
- ],
- "formatted_address" : "abc, City, State 123, country",
- "geometry" : {
- "bounds" : {
- "northeast" : {
- "lat" : 41.8683573,
- "lng" : -87.6126831
- },
- "southwest" : {
- "lat" : 41.86688609999999,
- "lng" : -87.6146402
- }
- },
- "location" : {
- "lat" : 41.8676217,
- "lng" : -87.6136616
- },
- },
- "place_id" : "ChIJny65eGMrDogRJ-qe3QJEuEo",
- "types" : [ "premise" ]
- }
- ],
- "status" : "OK"
- }
- JSONParser parser = JSON.createParser(res.getBody());
- double l1 = null;
- double l2 = null;
- while (parser.nextToken() != null) {
- System.debug('entred while');
- if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
- (parser.getText() == 'location')){
- parser.nextToken();
- while (parser.nextToken() != JSONToken.END_OBJECT){
- String txt = parser.getText();
- parser.nextToken();
- if (txt == 'lat')
- l1 = parser.getDoubleValue();
- else if (txt == 'lng')
- l2 = parser.getDoubleValue();
- }
- }
- }
- // i am storing values in Custom object
- if (l1 != null){
- customobj__c.Location__Latitude__s = l1;
- customobj__c.Location__Longitude__s = l2;
- update customobj__c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement