I am currently working on calculating the distance between 2 locations within an Angular 2 application using the Google Maps API.
Below are the necessary imports for utilizing the Google Maps API:
`
import {} from '@types/googlemaps';
import { AgmCoreModule, MapsAPILoader } from "@agm/core";
Subsequently, I have created a function to test the distance calculation:
`
calculateDistance() {
const nyc = new google.maps.LatLng(40.715, -74.002);
const london = new google.maps.LatLng(51.506, -0.119);
const distance = google.maps.geometry.spherical.computeDistanceBetween(nyc, london);
console.log(distance)
}
`
However, upon testing, the following error is encountered: inline template:10:4 caused by: Cannot read property 'spherical' of undefined.
Suggestions have been made to include a specific script tag, but attempting to do so results in another error indicating that the Google Maps API is being added multiple times causing errors such as autocompletion not functioning correctly.