Google Map Circle Radius Fit To Map
I am facing a problem with a size(radius) of the circle to be fitted in map, considering the map zoom can be from 1 to ~19, you can see also in the picture below, in my case I have
Solution 1:
I found solution which counts the width/height of the view port of the map, and simply mad height/2 which would be the ideal radius of the circle
$("#create_zone_trap").click(function(){
//Set the circle in the middle of the screen
circle.setCenter(new google.maps.LatLng(map.getCenter());
var spherical = google.maps.geometry.spherical,
bounds = map.getBounds(),
cor1 = bounds.getNorthEast(),
cor2 = bounds.getSouthWest(),
cor3 = new google.maps.LatLng(cor2.lat(), cor1.lng()),
cor4 = new google.maps.LatLng(cor1.lat(), cor2.lng()),
height = spherical.computeDistanceBetween(cor1,cor3),
width = spherical.computeDistanceBetween( cor1, cor4);
//Fit the circle radius to the map
// 0.9 means 90% of the height
circle.setRadius((height/2) * 0.9);
});
Post a Comment for "Google Map Circle Radius Fit To Map"