javascript 谷歌地图只显示特定国家(地区)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19369558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:20:44  来源:igfitidea点击:

Display only a specific country (region) in google maps

javascriptgoogle-mapsgeolocationcountry

提问by Cristiano Sarmento

Is there any way to show only a specific country or region using the google maps API?

有没有办法使用谷歌地图 API 只显示特定的国家或地区?

回答by Mukund

It can be done using GeoMap API. Please check following url for reference.

可以使用 GeoMap API 来完成。请检查以下网址以供参考。

1) https://code.google.com/apis/ajax/playground/?type=visualization#geo_map

1) https://code.google.com/apis/ajax/playground/?type=visualization#geo_map

2) https://developers.google.com/chart/interactive/docs/gallery/geomap#regionsexample

2) https://developers.google.com/chart/interactive/docs/gallery/geomap#regionsexample

Here is the example to load US region map.

这是加载美国地区地图的示例。

<html>
<head>
  <script type='text/javascript' src='https://www.google.com/jsapi'></script>
  <script type='text/javascript'>
      google.load('visualization', '1', { 'packages': ['geomap'] });
      google.setOnLoadCallback(drawMap);

      function drawMap() {
          var data = google.visualization.arrayToDataTable([
            ['City', 'Popularity'],
            ['New York', 200],
            ['Boston', 300],
            ['Miami', 400],
            ['Chicago', 500],
            ['Los Angeles', 600],
            ['Houston', 700]
          ]);

          var options = {};
          options['region'] = 'US';
          options['colors'] = [0xFF8747, 0xFFB581, 0xc06000]; //orange colors
          options['dataMode'] = 'markers';
          options['width'] = '556px';

          var container = document.getElementById('map_canvas');
          var geomap = new google.visualization.GeoMap(container);
          geomap.draw(data, options);
      };

  </script>
</head>

<body>
    <div id='map_canvas'></div>
</body>

</html>