# Afstanden berekenen

Het is mogelijk om de afstand uit te rekenen van de POI ten opzichte van de woning. Voor deze berekening is de `geometry` library nodig, welke beschikbaar is via de Google Maps API. Let op dat deze standaard niet ingeladen wordt. Raadpleeg de documentatie van Google Maps hoe je deze inlaadt: [https://developers.google.com/maps/documentation/javascript/libraries.](https://developers.google.com/maps/documentation/javascript/libraries.)

```
function calculateDistance(poi, baseLocation)
{
    if (typeof google.maps.geometry === 'undefined') {
        console.warn("The distance cannot be calculated, the Geometry library in Google Maps is not loaded.");

        return false;
    }

    // Calculate the distance of the place to the main object.
    var fullDistance = google.maps.geometry.spherical.computeDistanceBetween(
        new google.maps.LatLng(poi.lat, poi.lng),
        new google.maps.LatLng(baseLocation.lat, baseLocation.lng)
    );
}

console.log(calculateDistance(
    {lat: '53.194284', lng: '5.799072'}, 
    {lat:'53.194885', lng:'5.800822'}
));
```