【问题标题】:How do I find the north and south bound of a particular state in USA我如何找到美国特定州的北部和南部边界
【发布时间】:2023-03-07 18:37:01
【问题描述】:

我正在尝试实现 google maps API 的限制视图。

找不到相同的南北坐标。

有什么 API 吗?

【问题讨论】:

  • 对状态进行地理编码。在响应中使用边界。

标签: javascript google-maps geocoder


【解决方案1】:

您可以使用Geocoding API 获取状态边界。有一个方便的地理编码工具here

看看这个基于谷歌示例的工作jsfiddle,用于演示仅限于加利福尼亚州边界的地图。代码如下:

var map;
var CALIFORNIA_BOUNDS = {
  north: 42.009517,
  south: 32.528832,
  west: -124.482003,
  east: -114.131211
};
var CALIFORNIA = {
  lat: 36.778261,
  lng: -119.417932
};

function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: CALIFORNIA,
    restriction: {
      latLngBounds: CALIFORNIA_BOUNDS,
      strictBounds: false, // or true if you want
    },
    zoom: 7,
  });
}

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    相关资源
    最近更新 更多