【问题标题】:show postal code/zip code bounds on google map在谷歌地图上显示邮政编码/邮政编码范围
【发布时间】:2012-01-25 17:43:12
【问题描述】:

我想在地图上标记邮政编码的轮廓(边界)。使用谷歌地图 API,我可以发送邮政编码或地址并返回日志/纬度,然后在地图上放置一个图标。现在我想在邮政编码覆盖的整个区域周围制作一个盒子或多边形。是否有 API 或方法可以做到这一点?如果可以的话,我可以使用谷歌地图或其他服务。

获取邮政编码的纬度/经度的 API...

if (geocoder)           {       
    geocoder.geocode({ 'address': address }, function (results, status) {                  
        if (status == google.maps.GeocoderStatus.OK){
            var pcode = results[0].address_components[0].long_name;
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();                 
        }
    }

【问题讨论】:

    标签: google-maps zip geocoding postal-code


    【解决方案1】:
    geocoder.geocode({ 'address': address }, function (results, status) {
    
        if (status == google.maps.GeocoderStatus.OK) {
    
            var pcode = results[0].address_components[0].long_name;
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();
    
            //do whatever you want above then call the displayBounds function
            displayBounds(results[0].geometry.bounds);
        }
    });
    
    function displayBounds(bounds) {
    
        var rectangleOptions = {
            strokeColor: '#0000ff',
            strokeOpacity: 0.5,
            strokeWeight: 3,
            bounds: bounds
        }
    
        var rectangle = new google.maps.Rectangle(rectangleOptions);
    
        rectangle.setMap(map); //map being your google.maps.Map object
    }
    

    这样您就可以在地图上显示边界。不过,请确保您获得了结果的 geometry.bounds,因为并非总是如此。

    【讨论】:

    【解决方案2】:

    DisplayZipCodeArea(results[0].geometry.bounds, resultsMap);

    function DisplayZipCodeArea(bounds, resultsMap) {
    
        var rectangleOptions = {
            strokeColor: '#0000ff',
            strokeOpacity: 0.5,
            strokeWeight: 3,
            bounds: bounds
        }
    
        var rectangle = new google.maps.Rectangle(rectangleOptions);
    
        rectangle.setMap(resultsMap); //map being your google.maps.Map object
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      相关资源
      最近更新 更多