【问题标题】:Baloon location on map is incorrect地图上的气球位置不正确
【发布时间】:2016-08-19 14:24:02
【问题描述】:

我将 yandex 地图(谷歌地图的俄罗斯类似物)放在我的视野中。但是气球的位置与坐标不匹配!

代码如下:

示例 #1 - 气球显示不正确

<script type="text/javascript">
    ymaps.ready(init);
    var myMap,
        myPlacemark;

    function init() {
        myMap = new ymaps.Map("map", {
            center: [55.76, 37.64],
            zoom: 10
        });

        @foreach (var person in Model)
        {
            <text>
        console.log('Service = @person.ServiceName, x = @person.CoordinateX, y = @person.CoordinateY');

        myPlacemark = new ymaps.Placemark([@(person.CoordinateX), @(person.CoordinateY)], {
            hintContent: '@(person.ServiceName)',
            balloonContent: '@(person.CoordinateX), @(person.CoordinateY)'
        });
        myMap.geoObjects.add(myPlacemark);
            </text>
        }
    }
</script>

但是如果我把它改成常量(不在循环“foreach”中),一切正常:

示例 #2 - 气球显示正确

<script type="text/javascript">
    ymaps.ready(init);
    var myMap,
        myPlacemark;

    function init() {
        myMap = new ymaps.Map("map", {
            center: [55.76, 37.64],
            zoom: 10
        });

        myPlacemark = new ymaps.Placemark([55.871030, 37.658510], {
            hintContent: 'hint',
            balloonContent: 'content'
        });
        myMap.geoObjects.add(myPlacemark);

        myPlacemark = new ymaps.Placemark([55.782392, 37.614924], {
            hintContent: 'hint',
            balloonContent: 'content'
        });
        myMap.geoObjects.add(myPlacemark);
    }
</script>

注意: 在控制台中的示例 #1 中,我得到了正确的值:

服务 = something1,x = 55,87103,y = 37,65851

服务 = something2,x = 55,782392,y = 37,614924

但是气球的位置与坐标不匹配:

Incorrect baloons positions on map

【问题讨论】:

  • 你能举一个你传递给ymaps.Placemark的坐标例子吗?
  • 坐标示例:1) CoordinateX = 55.871030, CoordinateY = 37.658510; 2)坐标X = 55.782392,坐标Y = 37.614924
  • 我不知道 ASP.Net,但快速搜索让我对 &lt;text&gt;...&lt;/text&gt; 部分产生了怀疑。尝试删除地标创建代码周围的&lt;text&gt;“标签”(在@foreach中)。
  • 顺便说一句,如果您有指向问题页面的链接,请在此处发布,以便我更仔细地查看。
  • 另外,请确保您的模板不会在坐标而不是点中生成带有 逗号 的数字。

标签: javascript asp.net razor maps yandex-maps


【解决方案1】:

我们发现问题出在 ASP.Net 在发布的代码 sn-ps 中输出数字的方式上。它们以浮动逗号而不是点打印到 JS 代码中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多