Basically you need to create a simple Circle
, as shown on documentation , and set a value for the radius
property. For 2km, you need to put 2000 which is equivalent to 2 thousand meters. See:
var cityCircle = new google.maps.Circle({
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map,
center: {lat: -23.560362, lng: -46.587773},
radius: (2 * 1000)
});
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Circles</title>
<style>
#map {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var citymap = {
sampa: {
center: {lat: -23.560362, lng: -46.587773}
}
};
function initMap() {
// Cria o mapa
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: {lat: -23.560362, lng: -46.587773},
mapTypeId: 'terrain'
});
// Construct the circle for each value in citymap.
// Note: We scale the area of the circle based on the population.
for (var city in citymap) {
// Add the circle for this city to the map.
var cityCircle = new google.maps.Circle({
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map,
center: {lat: -23.560362, lng: -46.587773},
radius: (1 * 1000)
});
}
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDfXgMUO82be1sHgJlXHdg4JkTgN7qtm-M&callback=initMap">
</script>
</body>
</html>