I have a problem trying to get the currentLat(latitude) and currentLong(longitude) in the request param instead of the default value.If I take off the default values it says it does not exist. I know the values exist because it shows up in the console when I print it.
Here is my controller:
@Controller
public class MyController {
@Autowired
GroupRepository repo;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String Home(Model model, @RequestParam(defaultValue = "") String day,@RequestParam(defaultValue = "35.7754742") double currentLat, @RequestParam(defaultValue = "-78.6401854") double currentLong) {
model.addAttribute("day", day);
model.addAttribute("groups", repo.quickFind(LocalDateTime.now().getDayOfWeek().toString(),currentLat,currentLong));
model.addAttribute("groupsMonday", repo.listGroups("Monday",currentLat,currentLong));
model.addAttribute("groupsTuesday", repo.listGroups("Tuesday",currentLat,currentLong));
model.addAttribute("groupsWednesday", repo.listGroups("Wednesday",currentLat,currentLong));
model.addAttribute("groupsThursday", repo.listGroups("Thursday",currentLat,currentLong));
model.addAttribute("groupsFriday", repo.listGroups("Friday",currentLat,currentLong));
model.addAttribute("groupsSaturday", repo.listGroups("Saturday",currentLat,currentLong));
model.addAttribute("groupsSunday", repo.listGroups("Sunday",currentLat,currentLong));
System.out.println(currentLat+" "+currentLong);
return "index";
}
Here is my javascript to get the latitude and longitude:
$(document).ready(function() {
var lat;
var longt;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showPosition(position) {
lat = position.coords.latitude;
longt = position.coords.longitude;
console.log(lat+" "+longt);
$.get("/?currentLat=" + lat + "¤tLong=" + longt, function (result) {
console.log(result);
})
}
});