Skip to content

Instantly share code, notes, and snippets.

@Arc0re
Created February 10, 2017 13:07
Show Gist options
  • Save Arc0re/9bb8d82f1ee5c486d020124fde6242da to your computer and use it in GitHub Desktop.
Save Arc0re/9bb8d82f1ee5c486d020124fde6242da to your computer and use it in GitHub Desktop.
package com.example;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import se.walkercrou.places.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import se.walkercrou.places.exception.NoResultsFoundException;
import java.util.List;
import java.util.Map;
@RestController
public class RestoController {
final static String APIKEY = "AIzaSyAU3vOYPGy7eiTHA4aA53j43pbfqY_IxKQ";
@RequestMapping(value= "/restaurant", method = RequestMethod.GET)
public String restaurant(@RequestParam Map<String, String> requestParams) {
String lat = requestParams.get("lat");
String longi = requestParams.get("long");
String html = "";
if (lat != "" && longi != "") {
float latitude = Float.parseFloat(lat);
float longitude = Float.parseFloat(longi);
GooglePlaces client = new GooglePlaces(APIKEY);
List<Place> places = client.getNearbyPlaces(latitude, longitude, GooglePlacesInterface.MAXIMUM_RESULTS, Param.name("types").value(Types.TYPE_RESTAURANT), Param.name("radius").value(1000));
try {
for (Place place : places) {
html += "<p>Nom du restaurant : <strong>" + place.getName() + "</strong></p>";
html += "<em>Details <a target='blank_' href='restaurant/" + place.getPlaceId() + "'>ici</a></em>";
}
} catch (NoResultsFoundException ex) {
html += ex.getMessage();
}
}
return html;
}
@RequestMapping(value = "/error", method = RequestMethod.TRACE)
public String error() {
return "error";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment