【问题标题】:Google maps infowindow not showing on click in Symfony2 with VichGeographicalBundle使用 VichGeographicalBundle 在 Symfony2 中单击时未显示 Google 地图信息窗口
【发布时间】:2012-12-12 05:31:27
【问题描述】:

我已成功设置 VichGeographicalBundle 以在 Google 地图中显示一堆地点。一切正常,除了点击时不显示的信息窗口。

$this->setShowInfoWindowsForMarkers(true); 已设置,但似乎不起作用。

有什么想法吗?

编辑:

class allShopsMap extends Map
{
    /**
     * Constructs a new instance of LocationMap.
     */
    public function __construct(EntityManager $em)
    {
        parent::__construct();

        // configure your map in the constructor 
        // by setting the options

        $this->setShowZoomControl(true);
        $this->setZoom(13);
        $this->setAutoZoom(false);
        $this->setContainerId('map_canvas');
        $this->setWidth(980);
        $this->setHeight(360);
        $this->setShowInfoWindowsForMarkers(true);
        $this->setCenter(23.232323,23.232323);
        $this->setShowMapTypeControl(true);

        $query = $em->createQuery("SELECT st
                       FROM acme\ShopBundle\Entity\Shop sh 
                       WHERE sh.published = 1 ");
        $shops = $query->getResult();

        foreach ($shops as $shop) {
            $this->addMarker(new MapMarker($shop->getLatitude(), $shop->getLongitude(),$icon='images/map_marker.png'));
        }
    }
}

从树枝模板调用:

{{ vichgeo_map('allShops') }}

config.yml

vich_geographical:
    db_driver: orm 
    query_service: vich_geographical.query_service.default
    map_renderer: vich_geographical.map_renderer.google
    templating:
        engine: twig
        info_window: msgrShopBundle:Map:infoWindow.html.twig

services:
    msgr.map.allShops:
        class: msgr\ShopBundle\Map\allShopsMap  
        tags:
           -  { name: vichgeo.map, alias: allShops }
        arguments: 
            entityManager: "@doctrine.orm.entity_manager" 

{{ vichgeo_map('allShops') }} 生成的 HTML 代码:http://pastebin.com/jqvzG67N

【问题讨论】:

  • 显示错误的实时链接可能会帮助我们帮助您。还有发生错误的代码
  • 大卫,根本没有显示错误。我只需单击标记并没有显示任何内容。
  • 标记都成功显示在地图上,并且javascripts包含在中。 infoWindow 让我发疯,因为我通过 VichGeo 的代码进行了追踪,发现这里没有任何可疑之处。此外,firebug 中没有 js 错误。请帮忙。

标签: php symfony google-maps-api-3 google-maps-markers symfony-2.1


【解决方案1】:

试试这个:

class allShopsMap extends Map
{
    /**
     * Constructs a new instance of LocationMap.
     */
    public function __construct(EntityManager $em, $infoWindowBuilder)
    {
        parent::__construct();

        // configure your map in the constructor 
        // by setting the options

        $this->setShowZoomControl(true);
        $this->setZoom(13);
        $this->setAutoZoom(false);
        $this->setContainerId('map_canvas');
        $this->setWidth(980);
        $this->setHeight(360);
        $this->setShowInfoWindowsForMarkers(true);
        $this->setCenter(23.232323,23.232323);
        $this->setShowMapTypeControl(true);

        $query = $em->createQuery("SELECT st
                       FROM acme\ShopBundle\Entity\Shop sh 
                       WHERE sh.published = 1 ");
        $shops = $query->getResult();

        foreach ($shops as $shop) {
            $marker = new MapMarker($shop->getLatitude(), $shop->getLongitude(),$icon='images/map_marker.png');
            $marker->setInfoWindow($infoWindowBuilder->build($marker)); 
            $this->addMarker($marker);
        }
    }
}

infoWindowBuilder 是容器中可用的vich_geographical.info_window_builder 服务。

并修改你的配置:

services:
    msgr.map.allShops:
        class: msgr\ShopBundle\Map\allShopsMap  
        tags:
           -  { name: vichgeo.map, alias: allShops }
        arguments: 
            entityManager: "@doctrine.orm.entity_manager" 
            infoWindowBuilder: "@vich_geographical.info_window_builder"

【讨论】:

  • 我遇到了一个异常:[2/2] Twig_Error_Runtime:在渲染模板期间引发了异常(“警告:缺少参数 2 for ....allShopsMap::__construct() ,
  • meze:你认为你的代码中有一个解决方法来隐藏最后打开的 infoWindow 吗?发生的情况是,您单击的每个 infoWindow 都保持打开状态。
  • @RobertoDelgazzo,没有。不要认为 google api 有可能
猜你喜欢
  • 2020-07-22
  • 2018-02-24
  • 1970-01-01
  • 2011-02-24
  • 2018-07-28
  • 2012-05-25
  • 2011-11-07
  • 2019-04-02
  • 2023-03-30
相关资源
最近更新 更多