weixin_33696106 2017-05-26 01:35 采纳率: 0%
浏览 11

春季地理位置

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 + "&currentLong=" + longt, function (result) {
            console.log(result);
        })

    }
});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效