To show where the gravitational constant 'G' came from, it is necessary to consider how Newton derived his equation of universal gravitation from Kepler's laws of planetary motion. Kepler's laws are empirical (equations fitted to the data) and they are based upon the observational tables obtained by the astronomer Tycho Brahe.
Newton's law of universal gravitation may be derived from Kepler's laws. It is just this approach, that Newton adopted - starting with Kepler's second law (k2 for short). The element of area dA swept out by the radius vector, of an orbiting planet, in time dt is approximately: -
dA = ½r(r + dr)dθ
Hence, in the limit (calculus): -
dA = ½r²dθ
If k2 is written as: -
r²dθ/dt = constant = C or d(r²dθ/dt)/dt = 0
In this approximation the planets and the sun are considered to be point masses.
Now, from k1. The equation of an ellipse in polar coordinates with one focus as the origin is: -
1 - e.cosθ = (a(1 - r²))/r
Where a is the semi major axis and e is the eccentricity of the ellipse.
If we differentiate twice with respect to time and use K2 (constant form above) to eliminate dθ/dt, we obtain: -
(C²/r²).e.cosθ = - a(1 -e²).d²rdt²
A central conservative field of force has the potential equation: -
F = -dV/dr
From Newton's second law of motion it may be shown that the equation may be written down as: -
F(r) = m((d²r/dt²) - r.(dθ/dt)²)
.......= -(mC²/(a.(1 - e²)r²).(ecosθ +(a.(1 - e²)/r))
Hence, using K1 (from the above equation form): -
F(r) = -mC²/(a(1 - e²)r²)
If we now relate the constant C to the orbital period of the planet: -
dA/dt = 0.5C
With
A =√(πa²(1 - e²))
and this gives
√(πa²(1 - e²)) = 0.5CT
Hence, from the F(r) equation: -
F(r) = -4π²a³m/(T²r²) = -Bm/r²
Where B = 4π²a³/T²
Newton's great contribution was to realise that the forces between the earth and the sun were the same. Thus, for the sun (mass M): -
B/M = G
and for the earth (mass m constant B’)
B'/m = G
So that for the Sun, B = GM
Or
F = -GMm/r²
This is how Newton derived his famous equation using Kepler's empirical laws and the equation of a central conservative force field and found the gravitational constant G.
I hope this brief proof is of some assistance.