【问题标题】:Allow selection of country & zoom in only to country level允许选择国家并仅放大到国家级别
【发布时间】:2013-06-26 10:11:19
【问题描述】:

我想使用谷歌地图,但只能在国家级别使用,即我想在单个窗口中显示整个世界地图,用户应该能够通过点击国家来选择任何国家,我也应该能够显示一些弹出窗口.我也想从JS中选择国家的价值。请指导我。我对此进行了谷歌搜索,但没有完整的信息。

【问题讨论】:

  • 感谢您输入 Zoom to country 的问题示例是我们需要从下拉列表中选择国家 用户无法放置鼠标并选择并突出显示
  • 不能真正“选择并突出显示”。您可以结合这 2 个示例,单击一个国家并缩放到地理编码器返回的边界。
  • 有选择多选的选项吗,可以只高亮吗

标签: javascript html google-maps maps


【解决方案1】:

结合这两个例子:

  1. Zoom to country
  2. clickable world map

click to zoom to country

var map=null;
var geocoder = null;
var kmlLayer = null;
var infoWindow = new google.maps.InfoWindow(); // InfoWindow

function openIW(layerEvt) {
  if (layerEvt.row) {
    var content = layerEvt.row['admin'].value;
  } else if (layerEvt.featureData) {
    var content = layerEvt.featureData.name;
  }
  document.getElementById('info').innerHTML = "you clicked on:<br>"+content;
  findAddress(content);
}

function initialize() {
  geocoder = new google.maps.Geocoder();
  var chicago = new google.maps.LatLng(36.4278,-15.9);
  var myOptions = {
    zoom: 2,
    center: chicago,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  google.maps.event.addListener(map, "click", function() {
    document.getElementById('info').innerHTML = "";
  });


  kmlLayer = new google.maps.KmlLayer('http://www.geocodezip.com/geoxml3_test/world_countries_kml.xml', {preserveViewport: true, suppressInfoWindows: true} );
  kmlLayer.setMap(map);

  google.maps.event.addListener(kmlLayer, 'click', openIW);

}    

function findAddress(address) {
  if ((address != '') && geocoder) {
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
         if (results && results[0] && results[0].geometry && results[0].geometry.viewport) 
           map.fitBounds(results[0].geometry.viewport);
         } else {
           alert("No results found");
         }
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }
}

【讨论】:

  • 是否有机会进行多项选择
  • 当然有。您只需定义功能并对其进行编码。
  • 合法地从谷歌地图创建图像的唯一方法是使用static maps(请阅读Terms of Service 或咨询您的律师以确定,IANAL)
  • 如果我是付费客户,那么我可以
  • IANAL(我不是律师)我不知道,这是您(或您的律师)的责任来决定。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 2012-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多