首页 > 解决方案 > 使用javascript php laravel在经度和纬度数据库中的条目重复

问题描述

我在这里停留了 24 小时,我一直在尝试获得不同的值。我正在获取每个学生的地址以及经度和纬度。

这是我的观点,我使用了 javascript:

    $(document).ready(function() {
    $("#dropdown").change(function() {
    var selVal = $(this).val();
    $("#textboxDiv").html('');
     $("#schoolloc").html('');

    if(selVal > 0) {
        for(var i = 1; i<= selVal; i++) {
             $("#textboxDiv").append('<input type="hidden" 
    value="student'+i+'" name="stud[]" />');
             $("#schoolloc").append('<input type="text" 
    name="studlocation[]" id="studlocation'+i+'" />');
        var input = document.getElementById('studlocation'+i+'');
        var autocomplete = new google.maps.places.Autocomplete(input);
    $("#slat").html('');
    $("#slng").html('');
    autocomplete.addListener('place_changed', function () {
     var place = autocomplete.getPlace();
    var lat = place.geometry.location.lat();
    var lng= place.geometry.location.lng();
     $("#slat").append('<input type="hidden" name="slat" value="'+lat+'" />');
    $("#slng").append('<input type="hidden" name="slng" value="'+lng + '" />');
       console.log(lat);
         });
                   }

               }
                });
              });

这是我的控制器:

 $students = (array)$request->stud;
 $locations = (array)$request->studlocation;

 for ($i = 0; $i < count($students); $i++){

$hm = new HouseMate;

$hmid = rand();
$hm->hmid=$hmid;
$hm->rId_fk=$renterid;
$hm->person=$students[$i];  
$hm->location=$locations[$i];
$hm->$lat=$request->slat;
 $hm->lng=$request->slng;


$hm->save();

}

标签: javascriptphpdatabaselaravelautocomplete

解决方案


推荐阅读