mercredi 6 avril 2016

Laravel form request with geocoder

I have form in my view that is made of checkboxes, some textfields and selects.

On the same page I have googlemap geocoder. The location lat&lng is saved in variables in 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);
        }

    });

}

And in my controller I have POST function to save form in database.

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

In my DB I have columns for lat and lng and I want to add variables and the problem is that I can't add this 2 variables into $input variable in my controller. Help me please! :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire