2016-04-06 13 views
1

私はフォームの中にチェックボックス、テキストフィールド、選択するフォームがあります。ジオコーダを使用したLaravelフォームのリクエスト

同じページに私はgooglemapジオコーダを持っています。場所の緯度& 1ngがjavascriptの変数に保存されます。

screenshoot of webpage form

function geocodeAddress(geokodiranje, resultsMap) { 
    var address = document.getElementById('address').value; 
    var location = {}; 
    geokodiranje.geocode({'address': address}, function(results, status) { 
     if (status === google.maps.GeocoderStatus.OK) { 

      location.lattitude = results[0].geometry.location.lat(); 
      location.longitude = results[0].geometry.location.lng(); 

      resultsMap.setCenter(results[0].geometry.location); 
      var marker = new google.maps.Marker({ 
       map: resultsMap, 
       position: results[0].geometry.location 
      }); 
      lat = location.lattitude; //THIS IS MY LAT 
      lng = location.longitude; //THIS IS MY LNG 
     } else { 
      alert('Geocode failed for reason: ' + status); 
     } 

    }); 

} 

そして、私のコントローラで私は、データベースにフォームを保存するためにPOST機能を持っています。私のDBで

$input = Request::all(); 
Blogpost::create($input); 
return redirect('other'); 

私は緯度とLNGの列を持っていると私は、変数を追加すると、問題は、私は私のコントローラで$入力変数には、この2つの変数を追加することはできませんということです。お願い助けて! :)あなたのようなフォームで緯度と経度2隠しフィールドを追加する必要が

答えて

1

この方法のようなjsのコードで
<input type="hidden" name="lat" class="lat" /> 
<input type="hidden" name="lon" class="lon" /> 

そして、設定された値:

function geocodeAddress(geokodiranje, resultsMap) { 
var address = document.getElementById('address').value; 
var location = {}; 
geokodiranje.geocode({'address': address}, function(results, status) { 
    if (status === google.maps.GeocoderStatus.OK) { 

     location.lattitude = results[0].geometry.location.lat(); 
     location.longitude = results[0].geometry.location.lng(); 

     resultsMap.setCenter(results[0].geometry.location); 
     var marker = new google.maps.Marker({ 
      map: resultsMap, 
      position: results[0].geometry.location 
     }); 
     lat = location.lattitude; //THIS IS MY LAT 
     lng = location.longitude; //THIS IS MY LNG 
     $('.lat').val(lat); 
     $('.lon').val(lng); 
    } else { 
     alert('Geocode failed for reason: ' + status); 
    } 

}); 

}

+0

感謝あなたは非常に:) – mercyFREAK

関連する問題