sam
sam

Reputation: 21

Getting Updated Radius/Area in Google Maps API v3

I have a map on our site that people can draw on to submit an area for marketing consideration. We finally have it mostly updated to the new v3 API, but I seem to be missing one function. When you edit a circle or polygon, the radius/area display beneath the map doesn't adjust with the edits. I think the problem lies in this snippet of code, but I'm not sure. Any ideas? (Working example here)

var map;
var poly;
function initialize() {

map = new google.maps.Map(
    document.getElementById('map'), {
      center: new google.maps.LatLng(40.3749, -75.2988),
      zoom: 15,
  disableDoubleClickZoom: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
  });

//map.clearOverlays();

//map.enableGoogleBar();

featureTable_ = document.getElementById("featuretbody");

select("hand_b");

}

google.maps.event.addDomListener(window, 'load', initialize);


function calcCircleArea(radius)

{

 var area = 0;

 area = (Math.PI * (radius * radius));

 return area;

}

function updateCircle(circle,point)

{



circle_bounds = circle.getBounds();

c_vertex  = circle_bounds.getCenter();

var distance = c_vertex.distanceFrom(point);

circle.setMap(null);

circle = drawCircle(c_vertex, distance,20, '#ff0000', 1, 0.5, '#ff0000', 0.5);

}

function drawCircle(center, radius, nodes, line_color, liWidth, line_opacity, fill_color, fill_opacity)

{

// calc km/degree

var latC = center.distanceFrom(new google.maps.LatLng(center.lat()+0.1, center.lng()))/100;

var lngC = center.distanceFrom(new google.maps.LatLng(center.lat(), center.lng()+0.1))/100;



//calc circle points 

var points = [];

var step = parseInt(360/nodes)||10;

for(var i=0; i<=360; i+=step)

{

var pint = new google.maps.LatLng(

center.lat() + (radius/latC * Math.cos(i * Math.PI/180)), 

center.lng() + (radius/lngC * Math.sin(i * Math.PI/180))

);

points.push(pint);

}

Upvotes: 1

Views: 446

Answers (1)

geocodezip
geocodezip

Reputation: 161334

removeOverlay is a v2 function as is GLatLng:

 map.removeOverlay(circle);

in v3 use:

circle.setMap(null);

Doesn't look like the code you posted is actually used in the live page. You probably want to add a radius_changed listener to the circle and update the calculation in there.

Upvotes: 1

Related Questions