-2

I am trying to implement the restriction view of google maps API.

Not able to find the north and south coordinates of the same.

Is there any API for it ?

1 Answers1

5

You can use the Geocoding API to get the state's bounds. There's a handy geocoder tool here.

Take a look at this working jsfiddle based off of Google's example for demonstration of a map restricted to California state bounds. Code below:

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,
  });
}

Hope this helps!

evan
  • 5,443
  • 2
  • 11
  • 20