Auto-center map with multiple markers in Google Maps API v3

后端 未结 8 1002
梦如初夏
梦如初夏 2020-12-07 06:38

This is what I use to display a map with 3 pins/markers:



        
8条回答
  •  遥遥无期
    2020-12-07 07:31

    I use the method above to set the map boundaries, then, instead of resetting the zoom level, I just calculate the average LAT and average LON and set the center point to that location. I add up all the lat values into latTotal and all the lon values into lontotal and then divide by the number of markers. I then set the map center point to those average values.

    latCenter = latTotal / markercount; lonCenter = lontotal / markercount;

提交回复
热议问题