标记在重新加载页面后消失:AngularJS

Marker disappears after reloading page: AngularJS

本文关键字:消失 AngularJS 加载 新加载      更新时间:2023-12-07

我面临着一个奇怪的情况。在加载第一页时,以下代码在给定坐标处正确显示标记,并且地图正确居中:

<div class="paddingtop">
    <map data-ng-model="mymapdetail" zoom="11" center="{{item.coordinates}}" style="heigth:375px">
        <marker position="[{{item.coordinates}}]" icon="./images/i.png" />
      <control name="overviewMap" opened="true" />      
    </map>
</div>

正如您可能注意到的,在第一个标记中,我不包括方括号,方括号包含在第二个标记(标记)中。这样,标记就出现了。

当我重新加载页面或返回此页面时,标记不再存在。更准确地说,地图正确居中,但标记在地球上的位置完全不同(在非洲,而不是在迈阿密或其他美国城市)。

如果我在两者上都加上括号(中心和位置),我会得到以非洲为中心的地图和标记(这意味着出了问题,就好像我打印了他们在美国某个地方的坐标一样)。

这个代码出了什么问题?

为了完整起见,我可以说这段代码工作正常:

<map data-ng-model="mymap" zoom="4" center="[38.50, -95.00]" style="heigth:375px">
    <div ng-repeat="item in items">
      <marker position="[{{item.coordinates}}]" icon="./images/i.png" on-click="showInfoWindow('mbar')" />          
        <info-window id="mbar" >
            <div>
                {{item.name}}
            </div>
        </info-window>
    </div>            
      <control name="overviewMap" opened="true" />
</map>` 

去掉方括号可以解决问题,但这会带来一个新问题。AngularJS和Maps API:停止提示计算机';s位置