Google Maps API中的国家/地区特定缩放级别 [英] Country specific zoom level in Google Maps API

查看:113
本文介绍了Google Maps API中的国家/地区特定缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作只显示荷兰的Google地图。但是当我使用缩放级别6时,它会显示比利时和德国,当我使用缩放级别7时,它放大得太远,因为它没有显示完整的国家。



我该如何让荷兰队只展示自己,而不是德国和比利时(或者至少是其中的一小部分)。



目前看起来像这样:< br>

Mike Williams'v2 tutorial a>



工作示例

I'm trying to make a Google Map that only shows the Netherlands. But when I use zoom level 6 it shows Belgium and Germany as well and when I use zoom level 7 it zooms too far in that it doesn't show the complete country.

How can I make The Netherlands show only, and not germany and belgium (or at least a very tiny part of them).

Currently it looks something like this:

解决方案

  1. go to http://www.gadm.org/download, download the adm0 file for the Netherlands

  2. Combine that polygon (as the inner ring(s)) with a polygon that covers the whole earth

  3. use the winding reversal tool to reverse any inner polygons that don't wind opposite the outer ring.

  4. zip up the resulting kml, rename to kmz. Display on the map using geoxml3

Code:

function initialize() {
    var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
        center: new google.maps.LatLng(85.4419, -122.1419),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var geocoder = new google.maps.Geocoder();
    var geoXml = new geoXML3.parser({
                    map: map,
                    zoom: false, 
                 });
    geoXml.parse("http://www.geocodezip.com/geoxml3_test/kmz/nld_adm0_inverted.kmz");
    google.maps.event.addListener(geoXml,'parsed', function() {
      geocoder.geocode( { 'address': "Netherlands"}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.fitBounds(results[0].geometry.viewport);
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });    
    })
}
google.maps.event.addDomListener(window, "load", initialize);

Working example

To restrict it to be always displayed on the map see this page from Mike Williams' v2 tutorial

working example

这篇关于Google Maps API中的国家/地区特定缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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