Bing 地图添加多个图钉

发布于 2024-10-07 21:37:26 字数 102 浏览 0 评论 0原文

如何通过 Ajax API 将多个图钉添加到 Bing 地图 v7..?

它们可以从数组、列表、json 或其他任何地方加载。

有人可以提供一个小例子吗?谢谢

How to do add multiple pushpins to the Bing map v7 through Ajax API.. ?

They could be loaded from a array, list, json or anywhere else..

could someone provide a small example? Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-10-14 21:37:26

您可以使用 EntityCollection 添加多个图钉同时。


示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=de-de" type="text/javascript" charset="UTF-8"></script>
</head>
<body onload="init()">


<div id="map" style="position: relative; width: 800px; height: 300px;"></div>


<script type="text/javascript">
function init(){

    // Initialize the map
    var map = new Microsoft.Maps.Map(
        document.getElementById("map"),
        {
            credentials: "YOUR-BING-KEY",
            mapTypeId: Microsoft.Maps.MapTypeId.road
        }
    );


    // Creates a collection to store multiple pins
    var pins = new Microsoft.Maps.EntityCollection();

    // Creates 5 random pins
    for (var i = 0; i < 5; i++){
        // A random position
        var position = new Microsoft.Maps.Location(Math.random() * 45, Math.random() * 90);

        // Creates a Pushpin
        var pin = new Microsoft.Maps.Pushpin(position);

        // Adds the pin to the collection instead of adding it directly to the Map
        pins.push(pin);
    }

    // Adds all pins at once
    map.entities.push(pins);
}
</script>


</body>
</html>

此外,这里还有另一个 使用 JSON 和 jQuery 的示例

You can use EntityCollection to add several pins at the same time.


Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=de-de" type="text/javascript" charset="UTF-8"></script>
</head>
<body onload="init()">


<div id="map" style="position: relative; width: 800px; height: 300px;"></div>


<script type="text/javascript">
function init(){

    // Initialize the map
    var map = new Microsoft.Maps.Map(
        document.getElementById("map"),
        {
            credentials: "YOUR-BING-KEY",
            mapTypeId: Microsoft.Maps.MapTypeId.road
        }
    );


    // Creates a collection to store multiple pins
    var pins = new Microsoft.Maps.EntityCollection();

    // Creates 5 random pins
    for (var i = 0; i < 5; i++){
        // A random position
        var position = new Microsoft.Maps.Location(Math.random() * 45, Math.random() * 90);

        // Creates a Pushpin
        var pin = new Microsoft.Maps.Pushpin(position);

        // Adds the pin to the collection instead of adding it directly to the Map
        pins.push(pin);
    }

    // Adds all pins at once
    map.entities.push(pins);
}
</script>


</body>
</html>

Also, here another example using JSON and jQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文