I'm working on a project where I make a call to my API to get back GeoJSON for a 3 mile radius from a given address. It returns back towns for me in a feature collection by using PostGIS/Tiger. The data comes back correct and works.

I then load this data into Google Maps like so:


Is there a way to now take the geojson that is loaded, and center in on that point?

I have a feature collection of polygons for an address in a 5 mile radius. I was hoping I could just get the center without having to update my SQL query and return it from the API.

  • do you mean loadGeoJson? developers.google.com/maps/documentation/javascript/… Jul 19, 2017 at 4:56
  • What about using the point your using for your 3 mile radius? Isn't that waht you really want to center the view on? Then just use map.setCenter({lat:LAT_VALUE, lng:LONG_VALUE}); Jul 19, 2017 at 12:29
  • @BillChappell I'm taking an address the user types in, and then geocoding it to an area of GeoJSON. The response I get back is GeoJSON so I have to either parse that, or have my response include two things now (GeoJSON, and a long/lat to center in on which would have to be done on the database side). I don't mind doing it, but was hoping that there was a client-side way. Jul 19, 2017 at 21:40

1 Answer 1


If you may use js library, turfjs can do that. Take a look at http://turfjs.org/docs/#center . It is stated that "Takes a Featureor FeatureCollectionand returns the absolute center point of all features." You may zoom to returned point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.