0

In my Google Maps app the user can search for a place (using Autocomplete) and the map will be re-centered upon it with map.setCenter(pos);.

This does not change zoom level though, that must be done manually with map.setZoom(x).

In Google's map, zoom automatically readjusts to perfectly show the place's boundaries, how can I replicate that behavior?

James L.
  • 12,893
  • 4
  • 49
  • 60
  • 2
    Possible duplicate of [Determining zoom level from single LatLong in Google Maps API](https://stackoverflow.com/questions/312517/determining-zoom-level-from-single-latlong-in-google-maps-api) – woelliJ Jun 14 '17 at 19:02
  • Hey that's exactly it, thank you! edit: after looking it over and checking the google api, it appears that undocumented info has changed an is no longer available, so this question is not a duplicate :/ – James L. Jun 14 '17 at 19:18

1 Answers1

4

The duplicate @woelliJ found almost worked, but ended up using an old version of the API. It led me on the right track though, and I ended up finding how to make it work with the new API - map.fitBounds(autocomplete.getPlace().geometry.viewport);

James L.
  • 12,893
  • 4
  • 49
  • 60