dplsnw7329 2017-07-20 14:29
浏览 73
已采纳

Laravel googlemapper包,无法从配置文件中获取变量,“需要Google Maps API密钥。”错误

I was using your plugin these days trying to implement a googlemap on my site. I followed all installation steps and set a variety of variables. I am on laravel 5.4.

I stuck in this error: "Google maps API key is required.". Even I try to hard set the API in your core function, then it throws another error says "region is required". seems like the config file cannot be reached. I also tried to fix the file permissions, but unfortunately that's not the issue. Do you have any ideas about this? This is part of my controller file

use Cornford\Googlmapper\Mapper;
use Cornford\Googlmapper\Facades\MapperFacade;
use Illuminate\Support\Facades\Route;

public function index(Mapper $mapper)
{
    ............
    $firstMapItem = reset($mapArrays);
    $mapper->map(
    $firstMapItem->latitude, $firstMapItem->longitude,
    [
        'zoom' => 10,
        'markers' => ['title' => 'My Location', 'animation' => 'DROP'],
        'clusters' => ['size' => 10, 'center' => true, 'zoom' => 20]
    ]
    );

    // Add information window for each address
    foreach ($mapArrays as $mapArray) {
        $mapper->marker($mapArray->latitude, $mapArray->longitude);
    }
}

Route

Route::get( '/map', 'MapController@index');

view

<div style="width: 100%; height: auto;">
    {!! Mapper::render() !!}
</div>

BTW, I already changed the API value there, my problem is this API value has not been referenced. But if I move the Mapper function from the controller to the Route file, everything is fine. But if I do what I did as above, the API value from the googlmapper.php file isn't referenced.

  • 写回答

3条回答 默认 最新

  • doukong9316 2017-07-21 14:51
    关注

    Finally, make it works. Not because of the API issue, the API has been correctly placed. change

    use Cornford\Googlmapper\Mapper;
    

    to

    use Mapper;
    

    Very simply Facades things I think. credit to @zubinkadva on GitHub. Also the package author @bradcornford also mentioned

    "however for reference you can also use the following:

    use Cornford\Googlmapper\Facades\MapperFacade as Mapper; "

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来