I am trying to build a simple page the will display some places on the map. I'm really new to rest in Java and i'm using Spring boot + jersey framework.
I'm using google places api to search for places, i made the GET respond for a lat/lng that i'm passing thru PostMan:
http://localhost:9000/res/-23.558712/-46.592235
Inside the code im calling:
@GET
@Path("/{lat}/{lng}")
@Produces("application/json")
public void getBook(@PathParam("lat") String lat,@PathParam("lng") String lng) {
this.lat = lat;
this.lng = lng;
getdata();
}
public static void getdata(){
Client client = ClientBuilder.newClient();
String entity = client.target("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+ lat + "," + lng + "&radius=5000&types=market&name=dia&key=MY_KEY")
.request(MediaType.TEXT_PLAIN_TYPE)
.header("some-header", "true")
.get(String.class);
System.out.println(entity);
}
And i get a really big Json in the response:
"results" : [
{
"geometry" : {
"location" : {
"lat" : -23.5703071,
"lng" : -46.58153289999999
},
"viewport" : {
"northeast" : {
"lat" : -23.56895811970849,
"lng" : -46.5801839197085
},
"southwest" : {
"lat" : -23.5716560802915,
"lng" : -46.58288188029149
}
}
},....
And much more, my question is, how do i parse this JSON response to away that i can manage data? I want to get, name, location... to plot on the map. I will have to create a model class with all response parameters?
I really don't know if this is all wrong.
This resource falls under reverse geocoding and if you need name of the location you should get it from "fromatted_address" attiribute, and address components will give you exact address. The following link has some information which might help you further. [reverse geocoding] https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.