The error your code provides is: google.maps.geometry is undefined
From the documentation for the Google Maps API v3 , geometric functions are part of a library that is not loaded by default:
The concepts in this document refer to features available only in the google.maps.geometry library. This library is not loaded by default when you load the Javascript Maps API, but must be explicitly set using the bootstrap parameter of the libraries.
, Google, , API Google, libraries=geometry:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>
, z .
:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>
<script type="text/javascript">
var map;
function initialize()
{
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script>
function test()
{
var arr = new Array()
arr.push('51.5001524,-0.1262362');
arr.push('52.5001524,-1.1262362');
arr.push('53.5001524,-2.1262362');
arr.push('54.5001524,-3.1262362');
dibuV(arr);
}
function dibuV(area)
{
var a = new Array();
for(var i=0; i<area.length; i++)
{
var uno = area[i].split(",");
a[i] = new google.maps.LatLng(uno[0],uno[1]);
}
poligon = new google.maps.Polygon({
paths: a,
strokeColor: "#22B14C",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#22B14C",
fillOpacity: 0.35
})
poligon.setMap(map);
var z = new google.maps.geometry.spherical.computeArea(poligon.getPath());
alert(z);
}
</script>
</head>
<body onload="test();">
<div id="map_canvas"></div>
</body>
</html>