Map Logic Help - Java -


package com.blackdeveraux.lunchroulette.places;  import java.math.bigdecimal; import java.util.hashmap; import java.util.linkedlist; import java.util.list; import java.util.map;  @suppresswarnings("serial") public class searchdata extends hashmap<string, object>{     public static final string base_url =           "https://maps.googleapis.com/maps/api/place/nearbysearch/json";      @suppresswarnings("unchecked")     public list<place> buildplaces() {         linkedlist<place> places = new linkedlist<place>();          list<map<string, object>> results = (list<map<string, object>>)get("results");          for(map<string, object> data : results){             place place = new place();             try {                 place.setname((string) data.get("name"));                 place.setreference((string) data.get("reference"));                 map<string, object> geometry = (map<string, object>)data.get("geometry");                 map<string, bigdecimal> location = (map<string, bigdecimal>)geometry.get("location");                  place.setlatitude(location.get("lat").doublevalue());                 place.setlongitude(location.get("lng").doublevalue());                  places.add(place);             } catch (exception e) {                 e.printstacktrace();             }         }         return places;     } } 

need understanding map , list logic, little complicated me, maybe not i'm having trouble getting how code works. code original author can found here!

this reply comment. cannot put reply because limited numbers of characters have post answer.

your map has string key , object it's value. when value key "geometry" gets object. map still object in java. code, can structure of list of map.

each map has following : "name" key : "value of name" string "reference" key: "value reference" string "geometry" key: "value of geometry" map<string, object>  means, have map inside map. geometry map inside map data.  , still, geometry has map location.  ("location" key : "value of location" map<string, bigdecimal>).  , finally, location map this: "lat" key : "lat value" bigdecimal "lng"  key: "lng value" bigdecimal 

so map inside map inside map.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -