Has anyone ever come across a way set the google maps zoom level so that the window is a certain distance across?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Measure witdh of your map in current zoomlevel use
google.maps.geometry.spherical.computeDistanceBetween()andmap.getBounds()(see doku).If measured distance is wider when desired, divide it by two. If it’s smaller, multiply by two.
Do this until the calculated width gets smaller oder bigger than the target width and count how often you have to multiply or divide.
Add / subtact the number you’ve counted to your current zoomvalue to get your target zoomvalue.
Note: you can not fit your map to an exact width, because you’re limited to the fixed zoomlevels, so this is only an approximation.