【问题标题】:Cannot export gpx and kml files, laravel无法导出gpx和kml文件,laravel
【发布时间】:2021-03-30 17:18:14
【问题描述】:

我在使用 laravel 控制器导出 kml 和 gpx 文件时遇到问题:对于 json 导出,我使用函数

 public function mapExportJSON(Request $request) {
    $client = new Client();

    $http = $client->post(
        'https://myurl' , 
        [   
            'body' => json_encode(array('points' => $request->points)),
            'headers' => [
                'Cache-Control' => 'no-cache',
                'Content-type' => 'application/json',
            ]
        ]
    );

    $result = $http->getBody()->getContents();

    return response($result)
        ->header('Content-Disposition', 'attachment; filename=route.json');
}

我使用 xml 格式化程序,但它不起作用:(

    public function mapExportKML(Request $request) {
    $client = new Client();

    $http = $client->post(
        'https://myurl' , 
        [   
            'body' => json_encode(array('points' => $request->points)),
            'headers' => [
                'Cache-Control' => 'no-cache',
                'Content-type' => 'application/json',
            ]
        ]
    );

    $result = $http->getBody();

    $formatter = Formatter::make($result, Formatter::JSON);
    $xml  = $formatter->toXml();

    return response($xml)
        ->header('Content-Disposition', 'attachment; filename=route.kml')
        ->header('Content-Type', 'application/xml');

}

有人帮帮我吗?

【问题讨论】:

    标签: xml laravel export kml formatter


    【解决方案1】:

    看起来您使用的格式化程序不正确,请尝试以下操作

      $formatter = Formatter::make($result, Formatter::XML);
      $xml  = $formatter->toXml();
    

    【讨论】:

      猜你喜欢
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 2013-04-17
      • 2015-05-13
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多