如何显示在谷歌地图多个位置? [英] How do I show multiple locations in Google Maps?

查看:715
本文介绍了如何显示在谷歌地图多个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个经度和姿态数据,我想向他们展示了谷歌地图与针脚。

I have multiple longtitude and attitude data and I want to show them in the google map with pins.

如何使用谷歌地图API来做到这一点?

How to use the google map API to do this?

推荐答案

您遍历您的阵列,并为每一对创建一个新的标记实例。原因很简单:

You iterate over your array, and create a new Marker instance for each pair. It's simple:

<script>
    var map = new google.maps.Map(document.getElementById('map'), {
        center: new google.maps.LatLng(55.378051, -3.435973),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        zoom: 8
    });

    var locations = [
        new google.maps.LatLng(54.97784, -1.612916),
        new google.maps.LatLng(55.378051, -3.435973])
        // and additional coordinates, just add a new item
    ];

    locations.forEach(function (location) {
        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
    });
</script>

这适用于任何数量的经/纬度对;只需添加一个新的项目到地点阵列。

This works for any number of latitude/longitude pairs; just add a new item to the locations array.

这篇关于如何显示在谷歌地图多个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆