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条)

报告相同问题?

悬赏问题

  • ¥15 类图中关联与聚合的区别
  • ¥15 ENVI高分五号去除云层的方法
  • ¥15 16进制数据如何得到奇偶校验位
  • ¥15 求合并两个字节流VB6代码
  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系