bradcornford / Googlmapper

An easy way to integrate Google Maps with Laravel
MIT License
464 stars 142 forks source link

Load map from ajax request #294

Closed rddewan closed 4 years ago

rddewan commented 6 years ago

Hi How do i load map from ajax post request

//route Route::post('/gps/map/get_map','GpsLog\MapController@getMap');

//controller /*

//view

<div id="#map-holder" style="width: 100%; height: 80%;">
    {!! Mapper::render() !!}
</div>

<script type="text/javascript">
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $("#search_device").click(function () {
        $.ajax({
            url: '/gps/map/get_map',
            type : 'POST',
            data: {
                'deviceId' : $("#select_user option:selected").val(),
                'year' : $("#select_year option:selected").val(),
                'month' : $("#select_month option:selected").val(),
                'day' : $("#select_day option:selected").val()
            },
            success:function (data) {
                maps[0].map.setCenter({lat: data.latitude, lng: data.longitude});
            },
            error:function (xhr, status, error) {
                let responseText = JSON.parse(xhr.responseText),data = responseText['errorInfo'];
                swal({
                    title: "Error !",
                    text: "Status: " +xhr.status +" - Message: " + data + " - Error: " + error,
                    type: "error",
                    button: "OK",
                });
            }

        })
    })

</script>
bradcornford commented 6 years ago

Hi there,

Try looking over the following: https://github.com/bradcornford/Googlmapper/issues/91