Display only a specific country (region) in google maps [duplicate]

冷暖自知 提交于 2019-12-19 11:57:16

问题


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


回答1:


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

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

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>


来源:https://stackoverflow.com/questions/19369558/display-only-a-specific-country-region-in-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!